﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Teigha.Colors;
using Teigha.DatabaseServices;
using Teigha.Geometry;

namespace SRB.Tg.DrawingStandard
{
    public class RebarPLPloter
    {

        /// <summary>
        /// 顶层和底层布筋
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="Point">（最左边作为起点）参考点</param>
        /// <param name="radius">半径</param>
        /// <param name="topSp">间隔列表</param>
        /// <param name="sacle">比例尺</param>
        /// <param name="isOnLineUpper">是否在线上面</param>
        public static void CreateSingleLineHatch(Database db, ref Extents2d ext, Point2d Point, double radius,
         List<double> topSp, double sacle, double Dia, bool isOnLineUpper = true, string layer = "H粗线")
        {
            radius = radius * sacle;
            double width = 0;
            width = topSp.Sum();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                double curWidth = 0;

                //画线
                Polyline line = new Polyline() { Closed = false, LayerId = lt[layer] };//定义不封闭的Polyline 平面虚线

                line.AddVertexAt(0, Point.C2D(0, 0), 0, 0, 0);
                line.AddVertexAt(1, Point.C2D(width + Dia, 0), 0, 0, 0);

                recorder.AppendEntity(line);
                tr.AddNewlyCreatedDBObject(line, true);
                ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.C2D(), line.Bounds.Value.MaxPoint.C2D()));
                #region 
                curWidth = 0;
                for (int i = 0; i < topSp.Count + 1; i++)
                {
                    //画圆
                    Circle ci = new Circle();
                    if (isOnLineUpper)
                    {
                        ci.Center = Point.C3D(curWidth + Dia / 2, radius);
                    }
                    else
                    {
                        ci.Center = Point.C3D(curWidth + Dia / 2, -radius);
                    }
                    ci.Radius = radius;
                    ci.LayerId = lt[layer];
                    ci.SetDatabaseDefaults();//用来把圆的颜色、图层、线型、打印样式、可见性等属性设为实体所在的数据库的默认值
                    recorder.AppendEntity(ci);
                    tr.AddNewlyCreatedDBObject(ci, true);
                    ext = ext.Add(new Extents2d(ci.Bounds.Value.MinPoint.C2D(), ci.Bounds.Value.MaxPoint.C2D()));
                    //圆填充
                    ObjectIdCollection collection = new ObjectIdCollection();
                    collection.Add(ci.ObjectId);
                    Hatch hatch = new Hatch();
                    hatch.Elevation = 0;
                    hatch.HatchStyle = HatchStyle.Normal;
                    hatch.LayerId = lt[layer];
                    hatch.SetDatabaseDefaults();
                    hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID"); //设置填充图案
                    hatch.AppendLoop(HatchLoopTypes.Default, collection); //设置填充边界 //
                    hatch.EvaluateHatch(true);
                    recorder.AppendEntity(hatch);
                    tr.AddNewlyCreatedDBObject(hatch, true);
                    if (i < topSp.Count)
                        curWidth += topSp[i];
                }

                #endregion


                tr.Commit();
            }
        }

        /// <summary>
        /// 侧面布筋
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="Point">（最下面作为起点）参考点</param>
        /// <param name="radius">半径</param>
        /// <param name="topSp">侧面间隔集合</param>
        /// <param name="sacle">比例尺</param>
        /// <param name="bH">底层钢筋高度</param>
        /// <param name="isOnLineRight">是否在右边</param>
        public static void CreateSideSingleLineHatch(Database db, ref Extents2d ext, Point2d Point, double radius,
    List<double> sideSp, double sacle, double Dia, double bH = 0, bool isOnLineRight = true, string layer = "H粗线", bool isAddDia = false)
        {
            radius = radius * sacle;
            double height = 0;
            height = sideSp.Sum();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                double curHeight = 0;

                //画线
                Polyline line = new Polyline() { Closed = false, LayerId = lt[layer] };//定义不封闭的Polyline 平面虚线

                line.AddVertexAt(0, Point.C2D(0, -bH), 0, 0, 0);
                if (isAddDia)
                    line.AddVertexAt(1, Point.C2D(0, height + Dia / 2 + Dia / 2), 0, 0, 0);
                else
                    line.AddVertexAt(1, Point.C2D(0, height + Dia / 2), 0, 0, 0);

                recorder.AppendEntity(line);
                tr.AddNewlyCreatedDBObject(line, true);
                ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.C2D(), line.Bounds.Value.MaxPoint.C2D()));
                #region 
                curHeight = 0;
                for (int i = 0; i < sideSp.Count; i++)
                {
                    if (i > 0)
                    {
                        //画圆
                        Circle ci = new Circle();
                        if (isOnLineRight)
                        {
                            ci.Center = Point.C3D(radius, curHeight + Dia / 2);
                        }
                        else
                        {
                            ci.Center = Point.C3D(-radius, curHeight + Dia / 2);
                        }
                        ci.Radius = radius;
                        //ci.ColorIndex = 1;
                        ci.LayerId = lt[layer];
                        ci.SetDatabaseDefaults();//用来把圆的颜色、图层、线型、打印样式、可见性等属性设为实体所在的数据库的默认值
                        recorder.AppendEntity(ci);
                        tr.AddNewlyCreatedDBObject(ci, true);
                        ext = ext.Add(new Extents2d(ci.Bounds.Value.MinPoint.C2D(), ci.Bounds.Value.MaxPoint.C2D()));
                        //圆填充
                        ObjectIdCollection collection = new ObjectIdCollection();
                        collection.Add(ci.ObjectId);
                        Hatch hatch = new Hatch();
                        hatch.Elevation = 0;
                        hatch.HatchStyle = HatchStyle.Normal;
                        hatch.LayerId = lt[layer];
                        hatch.SetDatabaseDefaults();
                        hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID"); //设置填充图案
                        hatch.AppendLoop(HatchLoopTypes.Default, collection); //设置填充边界 //
                        hatch.EvaluateHatch(true);
                        recorder.AppendEntity(hatch);
                        tr.AddNewlyCreatedDBObject(hatch, true);
                    }
                    if (i < sideSp.Count)
                        curHeight += sideSp[i];
                }

                #endregion


                tr.Commit();
            }
        }


        /// <summary>
        /// 圆柱断面图
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="pt">圆柱左上切点</param>
        /// <param name="radius">圆柱半径</param>
        /// <param name="height">断面高度</param>
        /// <param name="isUp">true：上断面； false：下断面</param>
        public static void CreateCylindricalSection(Database db, ref Extents2d ext, Point3d pt,
            double radius, double height, bool isUp, double scale = 100)
        {
            DBObjectCollection res = new DBObjectCollection();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                double arcAngle = 60;
                double cosH = radius * Math.Cos(GeTools.DegreeToRadian(arcAngle / 2));
                if (isUp)
                {
                    // 绘制弧线
                    Arc arc1 = new Arc(pt.C3D(-radius / 2 * scale, -cosH * scale + height), radius * scale, GeTools.DegreeToRadian(60), GeTools.DegreeToRadian(60 + arcAngle)) { LayerId = lt["H细线"] };
                    ext = ext.Add(new Extents2d(arc1.Bounds.Value.MinPoint.C2D(), arc1.Bounds.Value.MaxPoint.C2D()));
                    res.Add(arc1);

                    Arc arc2 = new Arc(pt.C3D((radius / 2) * scale, -cosH * scale + height), radius * scale, GeTools.DegreeToRadian(60), GeTools.DegreeToRadian(60 + arcAngle)) { LayerId = lt["H细线"] };
                    ext = ext.Add(new Extents2d(arc2.Bounds.Value.MinPoint.C2D(), arc2.Bounds.Value.MaxPoint.C2D()));
                    res.Add(arc2);

                    Arc arc3 = new Arc(pt.C3D(-radius / 2 * scale, cosH * scale + height), radius * scale, GeTools.DegreeToRadian(240), GeTools.DegreeToRadian(240 + arcAngle)) { LayerId = lt["H细线"] };
                    ext = ext.Add(new Extents2d(arc3.Bounds.Value.MinPoint.C2D(), arc3.Bounds.Value.MaxPoint.C2D()));
                    res.Add(arc3);

                    // 直线
                    Polyline pl1 = new Polyline() { Closed = false, LayerId = lt["H粗线"] };

                    pl1.AddVertexAt(0, pt.C2D(-radius * scale, height), 0, 0, 0);
                    pl1.AddVertexAt(1, pt.C2D(-radius * scale), 0, 0, 0);
                    pl1.AddVertexAt(2, pt.C2D(radius * scale), 0, 0, 0);
                    pl1.AddVertexAt(3, pt.C2D(radius * scale, height), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                    res.Add(pl1);


                    // 中心线
                    Polyline pl4 = new Polyline() { Closed = false, LayerId = lt["H中心线"] };
                    pl4.AddVertexAt(0, pt.C2D(0, -5 * scale), 0, 0, 0);
                    pl4.AddVertexAt(1, pt.C2D(0, height + 5 * scale), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pl4.Bounds.Value.MinPoint.C2D(), pl4.Bounds.Value.MaxPoint.C2D()));
                    res.Add(pl4);
                }
                else
                {
                    // 绘制弧线
                    Arc arc1 = new Arc(pt.C3D(-radius / 2 * scale, -(height - cosH * scale)), radius * scale, GeTools.DegreeToRadian(240), GeTools.DegreeToRadian(240 + arcAngle)) { LayerId = lt["H细线"] };
                    ext = ext.Add(new Extents2d(arc1.Bounds.Value.MinPoint.C2D(), arc1.Bounds.Value.MaxPoint.C2D()));
                    res.Add(arc1);

                    Arc arc2 = new Arc(pt.C3D((radius / 2) * scale, -(height - cosH * scale)), radius * scale, GeTools.DegreeToRadian(240), GeTools.DegreeToRadian(240 + arcAngle)) { LayerId = lt["H细线"] };
                    ext = ext.Add(new Extents2d(arc2.Bounds.Value.MinPoint.C2D(), arc2.Bounds.Value.MaxPoint.C2D()));
                    res.Add(arc2);

                    Arc arc3 = new Arc(pt.C3D((radius / 2) * scale, -(height + cosH * scale)), radius * scale, GeTools.DegreeToRadian(60), GeTools.DegreeToRadian(60 + arcAngle)) { LayerId = lt["H细线"] };
                    ext = ext.Add(new Extents2d(arc3.Bounds.Value.MinPoint.C2D(), arc3.Bounds.Value.MaxPoint.C2D()));
                    res.Add(arc3);

                    // 直线
                    Polyline pl1 = new Polyline() { Closed = false, LayerId = lt["H粗线"] };
                    pl1.AddVertexAt(0, pt.C2D(-radius * scale, -height), 0, 0, 0);
                    pl1.AddVertexAt(1, pt.C2D(-radius * scale), 0, 0, 0);
                    pl1.AddVertexAt(2, pt.C2D(radius * scale), 0, 0, 0);
                    pl1.AddVertexAt(3, pt.C2D(radius * scale, -height), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                    res.Add(pl1);

                    // 中心线
                    Polyline pl4 = new Polyline() { Closed = false, LayerId = lt["H中心线"] };
                    pl4.AddVertexAt(0, pt.C2D(0, 5 * scale), 0, 0, 0);
                    pl4.AddVertexAt(1, pt.C2D(0, -height - 5 * scale), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pl4.Bounds.Value.MinPoint.C2D(), pl4.Bounds.Value.MaxPoint.C2D()));
                    res.Add(pl4);
                }

                foreach (DBObject drawitem in res)
                {
                    recorder.AppendEntity((Entity)drawitem);
                    tr.AddNewlyCreatedDBObject(drawitem, true);
                }
                tr.Commit();
            }
        }

        /// <summary>
        /// 箭头标注
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="refpt"></param>
        /// <param name="arrDir"></param>
        /// <param name="leftSp"></param>
        /// <param name="topSp"></param>
        /// <param name="textstring"></param>
        /// <param name="scale"></param>
        /// <param name="isLastVisible"></param>
        /// <param name="length"></param>
        public static void CreateLineArrowDB(Database db, ref Extents2d ext, Point3d refpt, ArrowDirection arrDir, List<double> leftSp, List<double> topSp, string textstring = "1", double scale = 1, bool isLastVisible = true, double length = 0)
        {
            double width = 0;
            double height = 0;
            width = topSp.Sum();
            height = leftSp.Sum();
            double curWidth = 0;
            double curHeight = 0;
            double cR = 2.5;
            DBText txt = new DBText();
            Circle C2 = new Circle();
            Point3d PositionPoint;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                Solid Array = new Solid();
                Line L = new Line() { LayerId = lt["H细线"] };
                switch (arrDir)
                {
                    case ArrowDirection.East:  //右
                        refpt = refpt.C3D(width, 0);
                        if (topSp.Count > 0)
                        {
                            for (int i = 0; i < topSp.Count; i++)
                            {
                                Array = new Solid(
                                 refpt.C3D(0 - curWidth, 0, 0),
                                 refpt.C3D(-1.35 * scale - curWidth, 0, 0),
                                  refpt.C3D(-1 * scale - curWidth, 0.3 * scale, 0)
                                 )
                                { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), LayerId = lt["H细线"], };
                                modelSpace.AppendEntity(Array);
                                tr.AddNewlyCreatedDBObject(Array, true);
                                curWidth += topSp[topSp.Count - 1 - i];
                                if (i == topSp.Count - 1 && isLastVisible)
                                {
                                    Array = new Solid(
                                 refpt.C3D(0 - curWidth, 0, 0),
                                 refpt.C3D(-1.35 * scale - curWidth, 0, 0),
                                  refpt.C3D(-1 * scale - curWidth, 0.5 * scale, 0)
                                 )
                                    { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), LayerId = lt["H细线"], };
                                    modelSpace.AppendEntity(Array);
                                    tr.AddNewlyCreatedDBObject(Array, true);
                                }
                            }
                        }
                        else
                        {
                            Array = new Solid(
                                 refpt.C3D(0 - curWidth, 0, 0),
                                 refpt.C3D(-1.35 * scale - curWidth, 0, 0),
                                  refpt.C3D(-1 * scale - curWidth, 0.5 * scale, 0)
                                 )
                            { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), LayerId = lt["H细线"], };
                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);
                        }
                        L = new Line(refpt.C3D(-width - (4 + length) * scale, 0, 0), refpt.C3D(0, 0, 0))
                        { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), LayerId = lt["H细线"], };
                        modelSpace.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);
                        PositionPoint = refpt.C3D(-width - (4 + length) * scale - cR * scale, 0, 0);
                        break;
                    case ArrowDirection.West:  //左
                        if (topSp.Count > 0)
                        {
                            for (int i = 0; i < topSp.Count; i++)
                            {
                                Array = new Solid(
                             refpt.C3D(0 + curWidth, 0, 0),
                             refpt.C3D(1.35 * scale + curWidth, 0, 0),
                              refpt.C3D(1 * scale + curWidth, 0.5 * scale, 0)
                             )
                                { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), LayerId = lt["H细线"], };

                                modelSpace.AppendEntity(Array);
                                tr.AddNewlyCreatedDBObject(Array, true);
                                curWidth += topSp[i];
                                if (i == topSp.Count - 1 && isLastVisible)
                                {
                                    Array = new Solid(
                             refpt.C3D(0 + curWidth, 0, 0),
                             refpt.C3D(1.35 * scale + curWidth, 0, 0),
                              refpt.C3D(1 * scale + curWidth, 0.5 * scale, 0)
                             )
                                    { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), LayerId = lt["H细线"], };

                                    modelSpace.AppendEntity(Array);
                                    tr.AddNewlyCreatedDBObject(Array, true);
                                }
                            }
                        }
                        else
                        {
                            Array = new Solid(
                           refpt.C3D(0 + curWidth, 0, 0),
                           refpt.C3D(1.35 * scale + curWidth, 0, 0),
                            refpt.C3D(1 * scale + curWidth, 0.5 * scale, 0)
                           )
                            { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), LayerId = lt["H细线"], };

                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);
                        }
                        L = new Line(refpt.C3D(width + (4 + length) * scale, 0, 0), refpt.C3D(0, 0, 0))
                        { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), LayerId = lt["H细线"], };
                        modelSpace.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);
                        PositionPoint = refpt.C3D(width + (4 + length) * scale + cR * scale, 0, 0);
                        break;
                    case ArrowDirection.South:  //下
                        refpt = refpt.C3D(0, -height);
                        if (leftSp.Count > 0)
                        {
                            for (int i = 0; i < leftSp.Count; i++)
                            {
                                Array = new Solid(
                             refpt.C3D(0, 0 + curHeight, 0),
                             refpt.C3D(0, 1.35 * scale + curHeight, 0),
                              refpt.C3D(0.5 * scale, 1 * scale + curHeight, 0)
                             )
                                { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), LayerId = lt["H细线"], };

                                modelSpace.AppendEntity(Array);
                                tr.AddNewlyCreatedDBObject(Array, true);
                                curHeight += leftSp[leftSp.Count - 1 - i];
                                if (i == leftSp.Count - 1 && isLastVisible)
                                {
                                    Array = new Solid(
                           refpt.C3D(0, 0 + curHeight, 0),
                           refpt.C3D(0, 1.65 * scale + curHeight, 0),
                            refpt.C3D(0.5 * scale, 1 * scale + curHeight, 0)
                           )
                                    { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), LayerId = lt["H细线"], };

                                    modelSpace.AppendEntity(Array);
                                    tr.AddNewlyCreatedDBObject(Array, true);
                                }
                            }
                        }
                        else
                        {
                            Array = new Solid(
                            refpt.C3D(0, 0 + curHeight, 0),
                            refpt.C3D(0, 1.35 * scale + curHeight, 0),
                             refpt.C3D(0.5 * scale, 1 * scale + curHeight, 0)
                            )
                            { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), LayerId = lt["H细线"], };

                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);
                        }
                        L = new Line(refpt.C3D(0, height + (4 + length) * scale, 0), refpt.C3D(0, 0, 0))
                        { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), LayerId = lt["H细线"], };
                        modelSpace.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);
                        PositionPoint = refpt.C3D(0, height + (4 + length) * scale + cR * scale, 0);
                        break;
                    case ArrowDirection.North:   //上
                        if (leftSp.Count > 0)
                        {
                            for (int i = 0; i < leftSp.Count; i++)
                            {
                                Array = new Solid(
                             refpt.C3D(0, 0 - curHeight, 0),
                             refpt.C3D(0, -1.35 * scale - curHeight, 0),
                              refpt.C3D(0.5 * scale, -1 * scale - curHeight, 0)
                             )
                                { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), LayerId = lt["H细线"], };

                                modelSpace.AppendEntity(Array);
                                tr.AddNewlyCreatedDBObject(Array, true);
                                curHeight += leftSp[i];
                                if (i == leftSp.Count && isLastVisible)
                                {
                                    Array = new Solid(
                            refpt.C3D(0, 0 - curHeight, 0),
                            refpt.C3D(0, -1.35 * scale - curHeight, 0),
                             refpt.C3D(0.5 * scale, -1 * scale - curHeight, 0)
                            )
                                    { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), LayerId = lt["H细线"], };

                                    modelSpace.AppendEntity(Array);
                                    tr.AddNewlyCreatedDBObject(Array, true);
                                }
                            }
                        }
                        else
                        {
                            Array = new Solid(
                             refpt.C3D(0, 0 - curHeight, 0),
                             refpt.C3D(0, -1.35 * scale - curHeight, 0),
                              refpt.C3D(0.5 * scale, -1 * scale - curHeight, 0)
                             )
                            { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), LayerId = lt["H细线"], };

                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);
                        }
                        L = new Line(refpt.C3D(0, -height - (4 + length) * scale, 0), refpt.C3D(0, 0, 0))
                        { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), LayerId = lt["H细线"], };
                        modelSpace.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);
                        PositionPoint = refpt.C3D(0, -height - (4 + length) * scale - cR * scale, 0);
                        break;
                    default:  //右
                        refpt = refpt.C3D(width, 0);
                        for (int i = 0; i < topSp.Count; i++)
                        {
                            Array = new Solid(
                             refpt.C3D(0 - curWidth, 0, 0),
                             refpt.C3D(-1.35 * scale - curWidth, 0, 0),
                              refpt.C3D(-1 * scale - curWidth, 0.5 * scale, 0)
                             )
                            { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), LayerId = lt["H细线"], };
                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);
                            curWidth += topSp[topSp.Count - 1 - i];
                        }
                        L = new Line(refpt.C3D(-width - (4 + length) * scale, 0, 0), refpt.C3D(0, 0, 0))
                        { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), LayerId = lt["H细线"], };
                        modelSpace.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);
                        PositionPoint = refpt.C3D(-width - (4 + length) * scale - cR * scale, 0, 0);
                        break;
                }
                ext = ext.Add(new Extents2d(Array.Bounds.Value.MinPoint.C2D(), Array.Bounds.Value.MaxPoint.C2D()));
                ext = ext.Add(new Extents2d(L.Bounds.Value.MinPoint.C2D(), L.Bounds.Value.MaxPoint.C2D()));
                txt.TextString = textstring.ToString();
                txt.Height = 2.5 * scale;
                txt.Position = PositionPoint.C3D();
                txt.HorizontalMode = TextHorizontalMode.TextCenter;
                txt.VerticalMode = TextVerticalMode.TextVerticalMid;
                txt.AlignmentPoint = PositionPoint.C3D();
                txt.TextStyleId = st[Extensions.curFont];
                txt.LayerId = lt["H标注"];
                //txt.LayerId = lt[layer];
                txt.WidthFactor = 0.8;

                C2 = new Circle(PositionPoint.C3D(), Vector3d.ZAxis, cR * scale);
                C2.LayerId = lt["H标注"];

                modelSpace.AppendEntity(txt);
                tr.AddNewlyCreatedDBObject(txt, true);
                modelSpace.AppendEntity(C2);
                tr.AddNewlyCreatedDBObject(C2, true);
                ext = ext.Add(new Extents2d(txt.Bounds.Value.MinPoint.C2D(), txt.Bounds.Value.MaxPoint.C2D()));
                ext = ext.Add(new Extents2d(C2.Bounds.Value.MinPoint.C2D(), C2.Bounds.Value.MaxPoint.C2D()));
                tr.Commit();
            }
        }

        /// <summary>
        /// 钢筋工点图
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="direction"></param>
        /// <param name="list"></param>
        /// <param name="T1"></param>
        /// <param name="bound">左右/上下元素个数分界线</param>
        /// <param name="midbound">左右/上下元素个数分界线</param>
        /// <param name="scale"></param>
        public static void CreateRebarPointLine(Database db, ref Extents2d ext, eDirection direction,
            List<Point3d> list, string T1, int bound, int midbound, double scale = 100, bool isleft = false, string layer = "H标注")
        {
            DBObjectCollection res = new DBObjectCollection();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                if (list == null || list.Count <= 1)
                {
                    return;
                }
                #region 绘制
                double height = 4 * scale;
                double angle = 70;
                double pointSpace = height / Math.Tan(GeTools.DegreeToRadian(angle));
                switch (direction)
                {
                    case eDirection.E_LEFT:
                        {
                            //if (Math.Abs(list[0].X - list[list.Count - 1].X) + 2.5 * scale <= pointSpace * (list.Count - 1))
                            //    break;
                            // 左边
                            for (int i = 0; i < bound && i < list.Count; ++i)
                            {
                                Polyline pl1 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl1.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl1.AddVertexAt(0, list[i].C2D(-height, -pointSpace), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl1);
                            }

                            // 右边
                            for (int i = list.Count - bound; i < list.Count; ++i)
                            {
                                Polyline pl2 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl2.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl2.AddVertexAt(0, list[i].C2D(-height, pointSpace), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl2);
                            }
                            // 左边中间
                            for (int i = list.Count / 2 - 3 - midbound; i < list.Count / 2 - 3 && i > 0; ++i)
                            {
                                Polyline pl1 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl1.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl1.AddVertexAt(0, list[i].C2D(-height, -pointSpace), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl1);
                            }

                            // 右边中间
                            for (int i = list.Count / 2 + 3; i < list.Count / 2 + 3 + midbound && i < list.Count; ++i)
                            {
                                Polyline pl2 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl2.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl2.AddVertexAt(0, list[i].C2D(-height, pointSpace), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl2);
                            }
                            double width = Math.Abs(list[list.Count - 1].C2D(-height, pointSpace).Y - list[0].C2D(-height, -pointSpace).Y) - 2.5 * 2 * scale;
                            Polyline pl3 = new Polyline() { Closed = false, LayerId = lt[layer] };
                            pl3.AddVertexAt(0, list[0].C2D(-height, -pointSpace), 0, 0, 0);
                            pl3.AddVertexAt(1, list[0].C2D(-height, -pointSpace - width / 2), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl3.Bounds.Value.MinPoint.C2D(), pl3.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pl3);

                            Polyline pl4 = new Polyline() { Closed = false, LayerId = lt[layer] };
                            pl4.AddVertexAt(0, list[list.Count - 1].C2D(-height, pointSpace + width / 2), 0, 0, 0);
                            pl4.AddVertexAt(1, list[list.Count - 1].C2D(-height, pointSpace), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl4.Bounds.Value.MinPoint.C2D(), pl4.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pl4);

                            // 圆形标记
                            DimPloter.CircularMark(db, ref ext, list[0].C3D(-height - 2.5 * scale, -pointSpace - width / 2 - 2.5 * scale),
                                T1, Extensions.curFont, scale);
                            break;
                        }
                    case eDirection.E_RIGHT:
                        {
                            //if (Math.Abs(list[0].X - list[list.Count - 1].X) + 2.5 * scale <= pointSpace * (list.Count - 1))
                            //    break;
                            // 左边
                            for (int i = 0; i < bound && i < list.Count; ++i)
                            {
                                Polyline pl1 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl1.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl1.AddVertexAt(0, list[i].C2D(height, -pointSpace), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl1);
                            }

                            // 右边
                            for (int i = list.Count - bound; i < list.Count; ++i)
                            {
                                Polyline pl2 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl2.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl2.AddVertexAt(0, list[i].C2D(height, pointSpace), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl2);
                            }
                            // 左边中间
                            for (int i = list.Count / 2 - 3 - midbound; i < list.Count / 2 - 3 && i > 0; ++i)
                            {
                                Polyline pl1 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl1.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl1.AddVertexAt(0, list[i].C2D(height, -pointSpace), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl1);
                            }

                            // 右边中间
                            for (int i = list.Count / 2 + 3; i < list.Count / 2 + 3 + midbound && i < list.Count; ++i)
                            {
                                Polyline pl2 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl2.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl2.AddVertexAt(0, list[i].C2D(height, pointSpace), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl2);
                            }
                            double width = Math.Abs(list[list.Count - 1].C2D(height, pointSpace).Y - list[0].C2D(height, -pointSpace).Y) - 2.5 * 2 * scale;
                            Polyline pl3 = new Polyline() { Closed = false, LayerId = lt[layer] };
                            pl3.AddVertexAt(0, list[0].C2D(height, -pointSpace), 0, 0, 0);
                            pl3.AddVertexAt(1, list[0].C2D(height, -pointSpace - width / 2), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl3.Bounds.Value.MinPoint.C2D(), pl3.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pl3);

                            Polyline pl4 = new Polyline() { Closed = false, LayerId = lt[layer] };
                            pl4.AddVertexAt(0, list[list.Count - 1].C2D(height, pointSpace + width / 2), 0, 0, 0);
                            pl4.AddVertexAt(1, list[list.Count - 1].C2D(height, pointSpace), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl4.Bounds.Value.MinPoint.C2D(), pl4.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pl4);

                            // 圆形标记
                            DimPloter.CircularMark(db, ref ext, list[0].C3D(height - 2.5 * scale, -pointSpace - width / 2 - 2.5 * scale),
                                T1, Extensions.curFont, scale);
                            break;
                        }
                    case eDirection.E_TOP:
                        {
                            //if (Math.Abs(list[0].X - list[list.Count - 1].X) - 2.5 * scale <= pointSpace * (list.Count - 1))
                            //    break;

                            // 左边
                            for (int i = 0; i < bound && i < list.Count; ++i)
                            {
                                Polyline pl1 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl1.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl1.AddVertexAt(0, list[i].C2D(pointSpace, -height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl1);
                            }

                            // 右边
                            for (int i = list.Count - bound; i < list.Count; ++i)
                            {
                                Polyline pl2 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl2.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl2.AddVertexAt(0, list[i].C2D(-pointSpace, -height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl2);
                            }
                            // 左边中间
                            for (int i = list.Count / 2 - 3 - midbound; i < list.Count / 2 - 3 && i > 0; ++i)
                            {
                                Polyline pl1 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl1.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl1.AddVertexAt(0, list[i].C2D(pointSpace, -height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl1);
                            }

                            // 右边中间
                            for (int i = list.Count / 2 + 3; i < list.Count / 2 + 3 + midbound && i < list.Count; ++i)
                            {
                                Polyline pl2 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl2.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl2.AddVertexAt(0, list[i].C2D(-pointSpace, -height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl2);
                            }
                            double width = list[list.Count - 1].C2D(-pointSpace, -height).X - list[0].C2D(pointSpace, -height).X - 2.5 * 2 * scale;
                            if (isleft)
                            {
                                width = list[list.Count - 1].C2D(-pointSpace, -height).X - list[0].C2D(pointSpace, -height).X;
                            }
                            Polyline pl3 = new Polyline() { Closed = false, LayerId = lt[layer] };
                            pl3.AddVertexAt(0, list[0].C2D(pointSpace, -height), 0, 0, 0);
                            pl3.AddVertexAt(1, list[0].C2D(pointSpace + width / 2, -height), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl3.Bounds.Value.MinPoint.C2D(), pl3.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pl3);

                            Polyline pl4 = new Polyline() { Closed = false, LayerId = lt[layer] };
                            pl4.AddVertexAt(0, list[list.Count - 1].C2D(-pointSpace - width / 2, -height), 0, 0, 0);
                            pl4.AddVertexAt(1, list[list.Count - 1].C2D(-pointSpace, -height), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl4.Bounds.Value.MinPoint.C2D(), pl4.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pl4);

                            if (isleft)
                            {
                                pl4 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl4.AddVertexAt(0, list[list.Count - 1].C2D(-pointSpace + 5 * scale, -height), 0, 0, 0);
                                pl4.AddVertexAt(1, list[list.Count - 1].C2D(-pointSpace, -height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl4.Bounds.Value.MinPoint.C2D(), pl4.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl4);
                                DimPloter.CircularMark(db, ref ext, list[list.Count - 1].C3D(-pointSpace + 5 * scale, -height),
                                T1, Extensions.curFont, scale);
                            }
                            else
                                // 圆形标记
                                DimPloter.CircularMark(db, ref ext, list[0].C3D(pointSpace + width / 2, -height),
                                    T1, Extensions.curFont, scale);
                            break;
                        }
                    case eDirection.E_BOTTOM:
                        {
                            //if (Math.Abs(list[0].X - list[list.Count - 1].X) - 2.5 * scale <= pointSpace * (list.Count - 1))
                            //    break;
                            // 左边
                            for (int i = 0; i < bound && i < list.Count; ++i)
                            {
                                Polyline pl1 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl1.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl1.AddVertexAt(0, list[i].C2D(pointSpace, height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl1);
                            }

                            // 右边
                            for (int i = list.Count - bound; i < list.Count; ++i)
                            {
                                Polyline pl2 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl2.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl2.AddVertexAt(0, list[i].C2D(-pointSpace, height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl2);
                            }
                            // 左边中间
                            for (int i = list.Count / 2 - 3 - midbound; i < list.Count / 2 - 3 && i > 0; ++i)
                            {
                                Polyline pl1 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl1.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl1.AddVertexAt(0, list[i].C2D(pointSpace, height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl1);
                            }

                            // 右边中间
                            for (int i = list.Count / 2 + 3; i < list.Count / 2 + 3 + midbound && i < list.Count; ++i)
                            {
                                Polyline pl2 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl2.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl2.AddVertexAt(0, list[i].C2D(-pointSpace, height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl2);
                            }
                            double width = list[list.Count - 1].C2D(-pointSpace, height).X - list[0].C2D(pointSpace, height).X - 2.5 * 2 * scale;
                            Polyline pl3 = new Polyline() { Closed = false, LayerId = lt[layer] };
                            pl3.AddVertexAt(0, list[0].C2D(pointSpace, height), 0, 0, 0);
                            pl3.AddVertexAt(1, list[0].C2D(pointSpace + width / 2, height), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl3.Bounds.Value.MinPoint.C2D(), pl3.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pl3);

                            Polyline pl4 = new Polyline() { Closed = false, LayerId = lt[layer] };
                            pl4.AddVertexAt(0, list[list.Count - 1].C2D(-pointSpace - width / 2, height), 0, 0, 0);
                            pl4.AddVertexAt(1, list[list.Count - 1].C2D(-pointSpace, height), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl4.Bounds.Value.MinPoint.C2D(), pl4.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pl4);

                            // 圆形标记
                            DimPloter.CircularMark(db, ref ext, list[0].C3D(pointSpace + width / 2, height),
                                T1, Extensions.curFont, scale);
                            break;
                        }
                    default:
                        break;
                }
                #endregion
                foreach (DBObject drawitem in res)
                {
                    recorder.AppendEntity((Entity)drawitem);
                    tr.AddNewlyCreatedDBObject(drawitem, true);
                }
                tr.Commit();
            }
        }


        public static void CreateBottomRebarPointLine(Database db, ref Extents2d ext,
         List<Point3d> list, int bottomNum, double bottomSpace, string T1, int bound, int midbound, double scale = 100,string layer="H标注")
        {
            DBObjectCollection res = new DBObjectCollection();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                if (list == null || list.Count <= 1)
                {
                    return;
                }
                #region 绘制
                double height = 3.2 * scale;
                double angle = 70;
                double pointSpace = height / Math.Tan(GeTools.DegreeToRadian(angle));


                for (int i = 0; i < bound && i < list.Count; ++i)
                {
                    Polyline pl1 = new Polyline() { Closed = false, LayerId = lt[layer] };
                    pl1.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                    pl1.AddVertexAt(0, list[i].C2D(pointSpace, height), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                    res.Add(pl1);
                    if (bottomNum > 0)
                    {
                        for (int m = 1; m < bottomNum; m++)
                        {
                            pl1 = new Polyline() { Closed = false, LayerId = lt[layer] };
                            pl1.AddVertexAt(0, list[i].C2D(0, -m * bottomSpace), 0, 0, 0);
                            pl1.AddVertexAt(0, list[i].C2D(pointSpace, height), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pl1);
                        }
                    }
                }

                // 右边
                for (int i = list.Count - bound; i < list.Count; ++i)
                {
                    Polyline pl2 = new Polyline() { Closed = false, LayerId = lt[layer] };
                    pl2.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                    pl2.AddVertexAt(0, list[i].C2D(-pointSpace, height), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                    res.Add(pl2);
                    if (bottomNum > 0)
                    {
                        for (int m = 1; m < bottomNum; m++)
                        {
                            pl2 = new Polyline() { Closed = false, LayerId = lt[layer] };
                            pl2.AddVertexAt(0, list[i].C2D(0, -m * bottomSpace), 0, 0, 0);
                            pl2.AddVertexAt(0, list[i].C2D(-pointSpace, height), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pl2);
                        }
                    }
                }
                // 左边中间
                for (int i = list.Count / 2 - 3 - midbound; i < list.Count / 2 - 3 && i > 0; ++i)
                {
                    Polyline pl1 = new Polyline() { Closed = false, LayerId = lt[layer] };
                    pl1.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                    pl1.AddVertexAt(0, list[i].C2D(pointSpace, height), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                    res.Add(pl1);
                    if (bottomNum > 0)
                    {
                        for (int m = 1; m < bottomNum; m++)
                        {
                            pl1 = new Polyline() { Closed = false, LayerId = lt[layer] };
                            pl1.AddVertexAt(0, list[i].C2D(0, -m * bottomSpace), 0, 0, 0);
                            pl1.AddVertexAt(0, list[i].C2D(pointSpace, height), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pl1);
                        }
                    }
                }

                // 右边中间
                for (int i = list.Count / 2 + 3; i < list.Count / 2 + 3 + midbound && i < list.Count; ++i)
                {
                    Polyline pl2 = new Polyline() { Closed = false, LayerId = lt[layer] };
                    pl2.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                    pl2.AddVertexAt(0, list[i].C2D(-pointSpace, height), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                    res.Add(pl2);
                    if (bottomNum > 0)
                    {
                        for (int m = 1; m < bottomNum; m++)
                        {
                            pl2 = new Polyline() { Closed = false, LayerId = lt[layer] };
                            pl2.AddVertexAt(0, list[i].C2D(0, -m * bottomSpace), 0, 0, 0);
                            pl2.AddVertexAt(0, list[i].C2D(-pointSpace, height), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pl2);
                        }
                    }
                }
                double width = list[list.Count - 1].C2D(-pointSpace, height).X - list[0].C2D(pointSpace, height).X - 2.5 * 2 * scale;
                Polyline pl3 = new Polyline() { Closed = false, LayerId = lt[layer] };
                pl3.AddVertexAt(0, list[0].C2D(pointSpace, height), 0, 0, 0);
                pl3.AddVertexAt(1, list[0].C2D(pointSpace + width / 2, height), 0, 0, 0);
                ext = ext.Add(new Extents2d(pl3.Bounds.Value.MinPoint.C2D(), pl3.Bounds.Value.MaxPoint.C2D()));
                res.Add(pl3);

                Polyline pl4 = new Polyline() { Closed = false, LayerId = lt[layer] };
                pl4.AddVertexAt(0, list[list.Count - 1].C2D(-pointSpace - width / 2, height), 0, 0, 0);
                pl4.AddVertexAt(1, list[list.Count - 1].C2D(-pointSpace, height), 0, 0, 0);
                ext = ext.Add(new Extents2d(pl4.Bounds.Value.MinPoint.C2D(), pl4.Bounds.Value.MaxPoint.C2D()));
                res.Add(pl4);

                // 圆形标记
                DimPloter.CircularMark(db, ref ext, list[0].C3D(pointSpace + width / 2, height),
                    T1, Extensions.curFont, scale);


                #endregion
                foreach (DBObject drawitem in res)
                {
                    recorder.AppendEntity((Entity)drawitem);
                    tr.AddNewlyCreatedDBObject(drawitem, true);
                }
                tr.Commit();
            }
        }


        /// <summary>
        /// 绘制承台平面图
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="startPt">绘制起点</param>
        /// <param name="arrayBarTop">外侧上下配筋</param>
        /// <param name="arrayBarLeft">外侧左右配筋</param>
        /// <param name="mainReinforcement">主筋横、纵向间距</param>
        /// <param name="pillarCenter">台柱中心点</param>
        /// <param name="pillarRadius">台柱半径</param>
        /// <param name="pillarWidth">承台宽度</param>
        /// <param name="pillarLength">承台长度</param>
        /// <param name="radius">配筋截面半径</param>
        /// <param name="CoverThk">厚度</param>
        /// <param name="scale">比例</param>
        public static void CreatePlotElevationEF(Database db, ref Extents2d ext, Point2d startPt,
            List<double> arrayBarTop, List<double> arrayBarLeft, List<double> ArrAlongWE, List<double> ArrAlongLE, List<Point3d> pillarCenter, double pillarRadius,
            double pillarWidth, double pillarLength, double radius, double CoverThk, int scale, Dictionary<int, int> dicNo, double N5Dia, double t2bSapceW, double t2bSapceL)
        {
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                DBObjectCollection res = new DBObjectCollection();
                #region 承台边框
                Polyline pl1 = new Polyline() { Closed = true, LayerId = lt["H细线"] };
                Point2d pt1 = startPt;
                Point2d pt2 = pt1.C2D(0, -pillarLength);
                Point2d pt3 = pt2.C2D(pillarWidth);
                Point2d pt4 = pt3.C2D(0, pillarLength);

                pl1.AddVertexAt(0, pt1, 0, 0, 0);
                pl1.AddVertexAt(1, pt2, 0, 0, 0);
                pl1.AddVertexAt(2, pt3, 0, 0, 0);
                pl1.AddVertexAt(3, pt4, 0, 0, 0);

                //ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                //res.Add(pl1);
                #endregion

                double reinforcementLength = 0;       // 纵向配筋长度
                double reinforcementwidth = 0;         // 横向配筋长度

                List<Point3d> vList = new List<Point3d>();      // 右边最外侧垂直圆心
                List<Point3d> hList = new List<Point3d>();      // 底部最下边横向圆心

                double offsetX = 0;
                for (int i = 0; i < arrayBarTop.Count; ++i)
                {
                    offsetX += arrayBarTop[i];
                }
                reinforcementLength = offsetX;

                double offsetY = 0;
                for (int i = 0; i < arrayBarLeft.Count; ++i)
                {
                    offsetY += arrayBarLeft[i];
                }
                reinforcementwidth = offsetY;
                #region 实心圆
                // 纵向
                Point3d pt = startPt.C3D(CoverThk + N5Dia * 0.5, -CoverThk - radius * scale);
                CreateSolidCircle(db, ref ext, pt, radius * scale);
                double marginX = 0;
                for (int i = 0; i < arrayBarTop.Count; ++i)
                {
                    if (i == 0 || i == arrayBarTop.Count - 1)
                    {
                        marginX += N5Dia * 0.5;
                    }
                    marginX += arrayBarTop[i];
                    pt = startPt.C3D(CoverThk + N5Dia + marginX, -CoverThk - radius * scale);
                    CreateSolidCircle(db, ref ext, pt, radius * scale);

                    CreateSolidCircle(db, ref ext, pt.C3D(0, -reinforcementwidth - radius * 2 * scale), radius * scale);
                    vList.Add(pt.C3D(0, -reinforcementwidth - radius * 2 * scale));
                }


                // 横向
                double marginY = 0;
                for (int i = 0; i < arrayBarLeft.Count; ++i)
                {
                    if (i == 0 || i == arrayBarLeft.Count - 1)
                    {
                        marginY += N5Dia * 0.5;
                    }
                    marginY += arrayBarLeft[i];

                    pt = startPt.C3D(CoverThk + radius * scale, -CoverThk - marginY - N5Dia * 0.5);

                    CreateSolidCircle(db, ref ext, pt, radius * scale);
                    CreateSolidCircle(db, ref ext, pt.C3D(reinforcementLength + radius * 2 * scale), radius * scale);
                    hList.Add(pt.C3D(reinforcementLength + radius * 2 * scale));
                }

                #endregion

                #region 台柱
                pt = startPt.C3D(pillarWidth / 4, -pillarLength / 4);
                Circle firstCircle = new Circle(pt.C3D(), Vector3d.ZAxis, pillarRadius);
                for (int i = 0; i < 2; ++i)
                {
                    for (int j = 0; j < 2; ++j)
                    {
                        pt = startPt.C3D(pillarWidth / 4 + pillarWidth / 2 * j, -pillarLength / 4 - pillarLength / 2 * i);
                        Circle a = new Circle(pt.C3D(), Vector3d.ZAxis, pillarRadius) { LayerId = lt["H粗线"] };
                        ext = ext.Add(new Extents2d(a.Bounds.Value.MinPoint.C2D(), a.Bounds.Value.MaxPoint.C2D()));
                        res.Add(a);
                    }
                }
                #endregion

                #region 外侧配筋
                // 纵向配筋
                Point3dCollection pts = new Point3dCollection();
                pt = startPt.C3D(CoverThk + radius * scale, -CoverThk - radius * scale);
                Polyline pl2 = new Polyline() { Closed = false, LayerId = lt["H粗线"] };
                Point2d p1 = pt.C2D(radius * scale, -radius * scale);
                Point2d p2 = p1.C2D(0, -reinforcementwidth);

                pl2.AddVertexAt(0, p1, 0, 0, 0);
                pl2.AddVertexAt(0, p2, 0, 0, 0);

                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                res.Add(pl2);

                marginX = 0;
                for (int i = 0; i < arrayBarTop.Count; ++i)
                {
                    if (i == 0 || i == arrayBarTop.Count - 1)
                    {
                        marginX += radius * scale;
                    }
                    marginX += arrayBarTop[i];
                    pt = startPt.C3D(CoverThk + radius * scale + marginX, -CoverThk - radius * scale);
                    Polyline pl3 = new Polyline() { Closed = false, LayerId = lt["H粗线"] };

                    if (i == arrayBarTop.Count - 1)
                    {
                        p1 = pt.C2D(-radius * scale, -radius * scale);
                        p2 = p1.C2D(0, -reinforcementwidth);
                    }
                    else
                    {
                        p1 = pt.C2D(0, -radius * scale);
                        p2 = p1.C2D(0, -reinforcementwidth);
                    }

                    pl3.AddVertexAt(0, p1, 0, 0, 0);
                    pl3.AddVertexAt(0, p2, 0, 0, 0);

                    ext = ext.Add(new Extents2d(pl3.Bounds.Value.MinPoint.C2D(), pl3.Bounds.Value.MaxPoint.C2D()));
                    res.Add(pl3);
                }

                // 横向配筋
                pt = startPt.C3D(CoverThk + radius * scale, -CoverThk - radius * scale);
                pl2 = new Polyline() { Closed = false, LayerId = lt["H粗线"] };
                p1 = pt.C2D(radius * scale, -radius * scale);
                p2 = p1.C2D(reinforcementLength);

                pl2.AddVertexAt(0, p1, 0, 0, 0);
                pl2.AddVertexAt(0, p2, 0, 0, 0);

                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                res.Add(pl2);

                marginY = 0;
                for (int i = 0; i < arrayBarLeft.Count; ++i)
                {
                    if (i == 0 || i == arrayBarLeft.Count - 1)
                    {
                        marginY += radius * scale;
                    }
                    marginY += arrayBarLeft[i];
                    pt = startPt.C3D(CoverThk + radius * scale, -CoverThk - marginY - radius * scale);
                    Polyline pl4 = new Polyline() { Closed = false, LayerId = lt["H粗线"] };


                    if (i == arrayBarLeft.Count - 1)
                    {
                        p1 = pt.C2D(radius * scale, radius * scale);
                        p2 = p1.C2D(reinforcementLength);
                    }
                    else
                    {
                        p1 = pt.C2D(radius * scale);
                        p2 = p1.C2D(reinforcementLength);
                    }
                    pl4.AddVertexAt(0, p1, 0, 0, 0);
                    pl4.AddVertexAt(0, p2, 0, 0, 0);



                    ext = ext.Add(new Extents2d(pl4.Bounds.Value.MinPoint.C2D(), pl4.Bounds.Value.MaxPoint.C2D()));
                    res.Add(pl4);
                }
                #endregion

                #region 主筋
                // 计算主筋数量
                offsetX = 0;
                offsetY = 0;
                List<List<Point3d>> ps = new List<List<Point3d>>();
                if (ArrAlongWE != null && ArrAlongLE != null)
                {
                    for (int i = 0; i < ArrAlongWE.Count; ++i)        // 行间隔
                    {
                        List<Point3d> list1 = new List<Point3d>();
                        offsetY += ArrAlongWE[i];
                        offsetX = 0;
                        for (int j = 0; j < ArrAlongLE.Count; ++j)  // 列间隔
                        {
                            offsetX += ArrAlongLE[j];
                            pt = startPt.C3D(CoverThk + radius * 3 * scale + offsetX, -CoverThk - offsetY - radius * scale);
                            CreateSolidCircle(db, ref ext, pt, radius * scale);
                            list1.Add(pt);
                        }
                        ps.Add(list1);
                    }
                }
                #endregion

                #region 标注和其他
                RotatedDimension dim0 = DimPloter.AddRotDim(db, ref ext, startPt.C3D(), startPt.C3D(0, -CoverThk - N5Dia * 0.5), startPt.C3D(-5 * scale),
                    scale, 90, Unit.Millimeter, Unit.Centimeter);
                //res.Add(dim0);

                RotatedDimension dim1 = DimPloter.AddRotDim(db, ref ext, startPt.C3D(0, -CoverThk - N5Dia * 0.5), startPt.C3D(0, -pillarLength + CoverThk + N5Dia * 0.5), startPt.C3D(-5 * scale),
                    scale, 90, Unit.Millimeter, Unit.Centimeter, "", "");
                //res.Add(dim1);

                RotatedDimension dim2 = DimPloter.AddRotDim(db, ref ext, startPt.C3D(0, -pillarLength + CoverThk + N5Dia * 0.5), startPt.C3D(0, -pillarLength), startPt.C3D(-5 * scale, -pillarLength),
                    scale, 90, Unit.Millimeter, Unit.Centimeter);
                //res.Add(dim2);

                RotatedDimension dim3 = DimPloter.AddRotDim(db, ref ext, startPt.C3D(), startPt.C3D(0, -pillarLength), startPt.C3D(-10 * scale),
                    scale, 90, Unit.Millimeter, Unit.Centimeter);
                //res.Add(dim3);


                RotatedDimension dim4 = DimPloter.AddRotDim(db, ref ext, startPt.C3D(), startPt.C3D(CoverThk + N5Dia * 0.5), startPt.C3D(0, 7 * scale),
                    scale, 0, Unit.Millimeter, Unit.Centimeter);
                //res.Add(dim4);

                RotatedDimension dim5 = DimPloter.AddRotDim(db, ref ext, startPt.C3D(CoverThk + N5Dia * 0.5), startPt.C3D(pillarWidth - CoverThk - N5Dia * 0.5), startPt.C3D(0, 7 * scale),
                    scale, 0, Unit.Millimeter, Unit.Centimeter);
                //res.Add(dim5);

                RotatedDimension dim6 = DimPloter.AddRotDim(db, ref ext, startPt.C3D(pillarWidth - CoverThk - N5Dia * 0.5), startPt.C3D(pillarWidth), startPt.C3D(0, 7 * scale),
                    scale, 0, Unit.Millimeter, Unit.Centimeter);
                //res.Add(dim6);

                RotatedDimension dim7 = DimPloter.AddRotDim(db, ref ext, startPt.C3D(), startPt.C3D(pillarWidth), startPt.C3D(0, 12 * scale),
                    scale, 0, Unit.Millimeter, Unit.Centimeter);
                //res.Add(dim7);
                #endregion

                #region 标记
                List<Point3d> list = new List<Point3d>();
                // 右侧标记
                int hIndex = 0;         // 标记外筋个数
                if (hList.Count <= 4)
                {
                    hIndex = 1;
                }
                else if (hList.Count > 4 && hList.Count <= 10)
                {
                    hIndex = 2;
                }
                else
                {
                    hIndex = 5;
                }
                if (hList != null && hList.Count > 0)
                {
                    for (int i = 0; i < hIndex && i < hList.Count - 1; ++i)
                    {
                        Point3d flg1 = hList[i];
                        list.Add(flg1.C3D(radius * scale));
                    }

                    for (int i = hList.Count - hIndex - 1; i < hList.Count; ++i)
                    {
                        Point3d flg1 = hList[i];
                        list.Add(flg1.C3D(radius * scale));
                    }

                    CreateRebarPointLine(db, ref ext, eDirection.E_RIGHT, list, dicNo[5].ToString(), list.Count / 2, list.Count / 2, scale);
                }

                // 底部标记
                list.Clear();
                int vIndex = 0;         // 标记外筋个数
                if (vList.Count <= 4)
                {
                    vIndex = 1;
                }
                else if (vList.Count > 4 && vList.Count <= 10)
                {
                    vIndex = 2;
                }
                else
                {
                    vIndex = 5;
                }
                if (vList != null && vList.Count > 0)
                {
                    for (int i = 0; i < vIndex && i < vList.Count - 1; ++i)
                    {
                        Point3d flg1 = vList[i];
                        list.Add(flg1.C3D(0, -radius * scale));
                    }

                    for (int i = vList.Count - vIndex - 1; i < vList.Count; ++i)
                    {
                        Point3d flg1 = vList[i];
                        list.Add(flg1.C3D(0, -radius * scale));
                    }

                    CreateRebarPointLine(db, ref ext, eDirection.E_TOP, list, dicNo[5].ToString(), list.Count / 2, list.Count / 2, scale);
                }

                // 主筋标记
                if (ps != null && ps.Count > 0)
                {
                    List<Point3d> l1 = new List<Point3d>();
                    Point2d pt7 = Point2d.Origin;
                    int startIndex = 0;
                    int lastIndex = 0;
                    if (ps.Count <= 3)
                    {
                        startIndex = 0;
                        lastIndex = ps.Count;
                    }
                    else
                    {
                        //startIndex = (ps.Count - 3) / 2;
                        startIndex = 0;
                        lastIndex = startIndex + 3;
                    }
                    //pt7 = ps[startIndex][ps[startIndex].Count - 1].C2D(20 * scale, 3 * scale);
                    double marginMarkCenter = 0;
                    if (ArrAlongWE != null && ArrAlongWE.Count > 0)
                    {
                        marginMarkCenter = ArrAlongWE[0];
                    }
                    pt7 = ps[startIndex][ps[startIndex].Count - 1].C2D(-3 * scale, CoverThk + radius * scale * 2 + marginMarkCenter);

                    int markCol = 2;            // 标记主筋列数
                    for (int i = startIndex; i < lastIndex && i < ps.Count; ++i)
                    {
                        int count = ps[i].Count;
                        markCol = count == 1 ? 1 : 2;
                        for (int j = count - markCol; j < count; ++j)
                        {
                            Polyline pll1 = new Polyline() { Closed = false, LayerId = lt["H粗线"] };
                            Point2d pt5 = ps[i][j].C2D();

                            pll1.AddVertexAt(0, pt5, 0, 0, 0);
                            pll1.AddVertexAt(0, pt7, 0, 0, 0);

                            ext = ext.Add(new Extents2d(pll1.Bounds.Value.MinPoint.C2D(), pll1.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pll1);
                        }
                    }

                    DimPloter.CircularMark(db, ref ext, pt7.C3D(-2.5 * scale, 2.5 * scale), dicNo[8].ToString(), Extensions.curFont, scale);
                }
                #endregion
                //ext = ext.Add(new Extents2d(dim0.Bounds.Value.MinPoint.C2D(), dim0.Bounds.Value.MaxPoint.C2D()));
                //ext = ext.Add(new Extents2d(dim1.Bounds.Value.MinPoint.C2D(), dim1.Bounds.Value.MaxPoint.C2D()));
                //ext = ext.Add(new Extents2d(dim2.Bounds.Value.MinPoint.C2D(), dim2.Bounds.Value.MaxPoint.C2D()));
                //ext = ext.Add(new Extents2d(dim3.Bounds.Value.MinPoint.C2D(), dim3.Bounds.Value.MaxPoint.C2D()));
                //ext = ext.Add(new Extents2d(dim4.Bounds.Value.MinPoint.C2D(), dim4.Bounds.Value.MaxPoint.C2D()));
                //ext = ext.Add(new Extents2d(dim5.Bounds.Value.MinPoint.C2D(), dim5.Bounds.Value.MaxPoint.C2D()));
                //ext = ext.Add(new Extents2d(dim6.Bounds.Value.MinPoint.C2D(), dim6.Bounds.Value.MaxPoint.C2D()));
                //ext = ext.Add(new Extents2d(dim7.Bounds.Value.MinPoint.C2D(), dim7.Bounds.Value.MaxPoint.C2D()));
                foreach (DBObject drawitem in res)
                {
                    recorder.AppendEntity((Entity)drawitem);
                    tr.AddNewlyCreatedDBObject(drawitem, true);
                }

                tr.Commit();


            }
        }

        /// <summary>
        /// 实心圆
        /// </summary>
        /// <param name="pt">圆点</param>
        /// <param name="radius">半径</param>
        /// <returns></returns>
        public static void CreateSolidCircle(Database db, ref Extents2d ext, Point3d pt, double radius)
        {
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                Circle circle = new Circle(pt, Vector3d.ZAxis, radius) { LayerId = lt["H细线"] };
                circle.SetDatabaseDefaults();//默认参数
                recorder.AppendEntity(circle);
                tr.AddNewlyCreatedDBObject(circle, true);
                ext = ext.Add(new Extents2d(circle.Bounds.Value.MinPoint.C2D(), circle.Bounds.Value.MaxPoint.C2D()));

                // 添加圆到一个 ObjectID 数组中去 
                ObjectIdCollection acObjIdColl = new ObjectIdCollection();
                acObjIdColl.Add(circle.ObjectId);

                // 创建图案填充对象并添加到块表记录中   
                Hatch hatch = new Hatch();
                //hatch.ColorIndex = 6;
                hatch.LayerId = lt["H细线"];
                recorder.AppendEntity(hatch);
                tr.AddNewlyCreatedDBObject(hatch, true);
                hatch.SetDatabaseDefaults();
                //hatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31");//ANSI31为金属剖面线
                hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID"); //设置填充图案
                hatch.Associative = true;
                hatch.AppendLoop(HatchLoopTypes.Outermost, acObjIdColl);
                hatch.EvaluateHatch(true);

                tr.Commit();
            }
        }


        public static void CreateBreakLine(Database db, ref Extents2d ext, Point2d stPoint, Point2d endPoint, double scale = 20,string layer= "H细线")
        {
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;
                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                #region
                Point2d centerPt = GeTools.MidPoint(stPoint.C3D(), endPoint.C3D()).C2D();
                //画线
                Polyline line = new Polyline() { Closed = false, LayerId = lt[layer], };//定义不封闭的Polyline 平面虚线
                if (stPoint.Y > endPoint.Y && stPoint.X == endPoint.X)
                {
                    line.AddVertexAt(0, stPoint, 0, 0, 0);
                    line.AddVertexAt(1, centerPt.C2D(0, 1.7941 * scale), 0, 0, 0);
                    line.AddVertexAt(2, centerPt.C2D(-2.4148 * scale, 1.147 * scale), 0, 0, 0);
                    line.AddVertexAt(3, centerPt, 0, 0, 0);
                    line.AddVertexAt(4, centerPt.C2D(2.4148 * scale, -1.147 * scale), 0, 0, 0);
                    line.AddVertexAt(5, centerPt.C2D(0, -1.7941 * scale), 0, 0, 0);
                    line.AddVertexAt(6, endPoint, 0, 0, 0);
                }
                else if (stPoint.Y <= endPoint.Y && stPoint.X == endPoint.X)
                {
                    line.AddVertexAt(0, endPoint, 0, 0, 0);
                    line.AddVertexAt(1, centerPt.C2D(0, 1.7941 * scale), 0, 0, 0);
                    line.AddVertexAt(2, centerPt.C2D(-2.4148 * scale, 1.147 * scale), 0, 0, 0);
                    line.AddVertexAt(3, centerPt, 0, 0, 0);
                    line.AddVertexAt(4, centerPt.C2D(2.4148 * scale, -1.147 * scale), 0, 0, 0);
                    line.AddVertexAt(5, centerPt.C2D(0, -1.7941 * scale), 0, 0, 0);
                    line.AddVertexAt(6, stPoint, 0, 0, 0);
                }

                if (stPoint.X > endPoint.X && stPoint.Y == endPoint.Y)
                {
                    line.AddVertexAt(0, stPoint, 0, 0, 0);
                    line.AddVertexAt(1, centerPt.C2D(1.7941 * scale, 0), 0, 0, 0);
                    line.AddVertexAt(2, centerPt.C2D(1.147 * scale, -2.4148 * scale), 0, 0, 0);
                    line.AddVertexAt(3, centerPt, 0, 0, 0);
                    line.AddVertexAt(4, centerPt.C2D(-1.147 * scale, 2.4148 * scale), 0, 0, 0);
                    line.AddVertexAt(5, centerPt.C2D(-1.7941 * scale, 0), 0, 0, 0);
                    line.AddVertexAt(6, endPoint, 0, 0, 0);
                }
                else if (stPoint.X <= endPoint.X && stPoint.Y == endPoint.Y)
                {
                    line.AddVertexAt(0, endPoint, 0, 0, 0);
                    line.AddVertexAt(1, centerPt.C2D(1.7941 * scale, 0), 0, 0, 0);
                    line.AddVertexAt(2, centerPt.C2D(1.147 * scale, -2.4148 * scale), 0, 0, 0);
                    line.AddVertexAt(3, centerPt, 0, 0, 0);
                    line.AddVertexAt(4, centerPt.C2D(-1.147 * scale, 2.4148 * scale), 0, 0, 0);
                    line.AddVertexAt(5, centerPt.C2D(-1.7941 * scale, 0), 0, 0, 0);
                    line.AddVertexAt(6, stPoint, 0, 0, 0);
                }
                recorder.AppendEntity(line);
                tr.AddNewlyCreatedDBObject(line, true);

                ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.C2D(), line.Bounds.Value.MaxPoint.C2D()));

                #endregion
                tr.Commit();
            }
        }

        /// <summary>
        /// 竖向
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="stPoint"></param>
        /// <param name="endPoint"></param>
        /// <param name="scale"></param>
        /// <param name="layer"></param>
        public static void CreateBreakLineV(Database db, ref Extents2d ext, Point2d stPoint, Point2d endPoint, double scale = 20, string layer = "H细线")
        {
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;
                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                #region
                Point2d centerPt = GeTools.MidPoint(stPoint.C3D(), endPoint.C3D()).C2D();
                //画线
                Polyline line = new Polyline() { Closed = false, LayerId = lt[layer], };//定义不封闭的Polyline 平面虚线
                if (stPoint.Y > endPoint.Y)
                {
                    line.AddVertexAt(0, stPoint, 0, 0, 0);
                    line.AddVertexAt(1, centerPt.C2D(0, 1.7941 * scale), 0, 0, 0);
                    line.AddVertexAt(2, centerPt.C2D(-2.4148 * scale, 1.147 * scale), 0, 0, 0);
                    line.AddVertexAt(3, centerPt, 0, 0, 0);
                    line.AddVertexAt(4, centerPt.C2D(2.4148 * scale, -1.147 * scale), 0, 0, 0);
                    line.AddVertexAt(5, centerPt.C2D(0, -1.7941 * scale), 0, 0, 0);
                    line.AddVertexAt(6, endPoint, 0, 0, 0);
                }
                else 
                {
                    line.AddVertexAt(0, endPoint, 0, 0, 0);
                    line.AddVertexAt(1, centerPt.C2D(0, 1.7941 * scale), 0, 0, 0);
                    line.AddVertexAt(2, centerPt.C2D(-2.4148 * scale, 1.147 * scale), 0, 0, 0);
                    line.AddVertexAt(3, centerPt, 0, 0, 0);
                    line.AddVertexAt(4, centerPt.C2D(2.4148 * scale, -1.147 * scale), 0, 0, 0);
                    line.AddVertexAt(5, centerPt.C2D(0, -1.7941 * scale), 0, 0, 0);
                    line.AddVertexAt(6, stPoint, 0, 0, 0);
                }

               
                recorder.AppendEntity(line);
                tr.AddNewlyCreatedDBObject(line, true);

                ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.C2D(), line.Bounds.Value.MaxPoint.C2D()));

                #endregion
                tr.Commit();
            }
        }
        /// <summary>
        /// 横向
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="stPoint"></param>
        /// <param name="endPoint"></param>
        /// <param name="scale"></param>
        /// <param name="layer"></param>
        public static void CreateBreakLineP(Database db, ref Extents2d ext, Point2d stPoint, Point2d endPoint, double scale = 20, string layer = "H细线")
        {
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;
                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                #region
                Point2d centerPt = GeTools.MidPoint(stPoint.C3D(), endPoint.C3D()).C2D();
                //画线
                Polyline line = new Polyline() { Closed = false, LayerId = lt[layer], };//定义不封闭的Polyline 平面虚线
                

                if (stPoint.X > endPoint.X )
                {
                    line.AddVertexAt(0, stPoint, 0, 0, 0);
                    line.AddVertexAt(1, centerPt.C2D(1.7941 * scale, 0), 0, 0, 0);
                    line.AddVertexAt(2, centerPt.C2D(1.147 * scale, -2.4148 * scale), 0, 0, 0);
                    line.AddVertexAt(3, centerPt, 0, 0, 0);
                    line.AddVertexAt(4, centerPt.C2D(-1.147 * scale, 2.4148 * scale), 0, 0, 0);
                    line.AddVertexAt(5, centerPt.C2D(-1.7941 * scale, 0), 0, 0, 0);
                    line.AddVertexAt(6, endPoint, 0, 0, 0);
                }
                else 
                {
                    line.AddVertexAt(0, endPoint, 0, 0, 0);
                    line.AddVertexAt(1, centerPt.C2D(1.7941 * scale, 0), 0, 0, 0);
                    line.AddVertexAt(2, centerPt.C2D(1.147 * scale, -2.4148 * scale), 0, 0, 0);
                    line.AddVertexAt(3, centerPt, 0, 0, 0);
                    line.AddVertexAt(4, centerPt.C2D(-1.147 * scale, 2.4148 * scale), 0, 0, 0);
                    line.AddVertexAt(5, centerPt.C2D(-1.7941 * scale, 0), 0, 0, 0);
                    line.AddVertexAt(6, stPoint, 0, 0, 0);
                }
                recorder.AppendEntity(line);
                tr.AddNewlyCreatedDBObject(line, true);

                ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.C2D(), line.Bounds.Value.MaxPoint.C2D()));

                #endregion
                tr.Commit();
            }
        }
        /// <summary>
        /// 箭头
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="refpt"></param>
        /// <param name="arrDir"></param>
        /// <param name="leftSp"></param>
        /// <param name="topSp"></param>
        /// <param name="textstring"></param>
        /// <param name="scale"></param>
        /// <param name="isLastVisible"></param>
        /// <param name="length"></param>
        /// <param name="leftLength">上下标注折线长度</param>
        public static void CreateLineArrowDBNew(Database db, ref Extents2d ext, Point3d refpt, ArrowDirection arrDir, List<double> leftSp, List<double> topSp, string textstring = "1", double scale = 1, bool isLastVisible = true, double length = 0, double leftLength = 0)
        {
            double width = 0;
            double height = 0;
            width = topSp.Sum();
            height = leftSp.Sum();
            double curWidth = 0;
            double curHeight = 0;
            double cR = 2.5;
            DBText txt = new DBText();
            Circle C2 = new Circle();
            Point3d PositionPoint;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                Solid Array = new Solid();
                Line L = new Line() { LayerId = lt["H细线"] };
                switch (arrDir)
                {
                    case ArrowDirection.East:  //右
                        refpt = refpt.C3D(width, 0);
                        if (topSp.Count > 0)
                        {
                            for (int i = 0; i < topSp.Count; i++)
                            {
                                Array = new Solid(
                                 refpt.C3D(0 - curWidth, 0, 0),
                                 refpt.C3D(-0.01 * scale - curWidth, 0, 0),
                                  refpt.C3D(-1 * scale - curWidth, 0.5 * scale, 0)
                                 )
                                { LayerId = lt["H细线"], };
                                modelSpace.AppendEntity(Array);
                                tr.AddNewlyCreatedDBObject(Array, true);
                                curWidth += topSp[topSp.Count - 1 - i];
                                if (i == topSp.Count - 1 && isLastVisible)
                                {
                                    Array = new Solid(
                                 refpt.C3D(0 - curWidth, 0, 0),
                                 refpt.C3D(-0.01 * scale - curWidth, 0, 0),
                                  refpt.C3D(-1 * scale - curWidth, 0.5 * scale, 0)
                                 )
                                    { LayerId = lt["H细线"], };
                                    modelSpace.AppendEntity(Array);
                                    tr.AddNewlyCreatedDBObject(Array, true);
                                }
                            }
                        }
                        else
                        {
                            Array = new Solid(
                                 refpt.C3D(0 - curWidth, 0, 0),
                                 refpt.C3D(-0.01 * scale - curWidth, 0, 0),
                                  refpt.C3D(-1 * scale - curWidth, 0.5 * scale, 0)
                                 )
                            { LayerId = lt["H细线"], };
                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);
                        }
                        L = new Line(refpt.C3D(-width - (1 + length) * scale, 0, 0), refpt.C3D(0, 0, 0))
                        { LayerId = lt["H细线"], };
                        modelSpace.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);
                        if (leftLength != 0)
                        {
                            L = new Line(refpt.C3D(-width - (1 + length) * scale, 0, 0), refpt.C3D(-width - (1 + length) * scale, leftLength, 0))
                            { LayerId = lt["H细线"], };
                            modelSpace.AppendEntity(L);
                            tr.AddNewlyCreatedDBObject(L, true);
                            if(leftLength>0)
                                PositionPoint = refpt.C3D(-width - (1 + length) * scale, leftLength+ cR * scale, 0);
                            else
                                PositionPoint = refpt.C3D(-width - (1 + length) * scale, leftLength - cR * scale, 0);
                        }
                        else
                             PositionPoint = refpt.C3D(-width - (1 + length) * scale - cR * scale, 0, 0);
                        break;
                    case ArrowDirection.West:  //左
                        if (topSp.Count > 0)
                        {
                            for (int i = 0; i < topSp.Count; i++)
                            {
                                Array = new Solid(
                             refpt.C3D(0 + curWidth, 0, 0),
                             refpt.C3D(0.01 * scale + curWidth, 0, 0),
                              refpt.C3D(1 * scale + curWidth, 0.5 * scale, 0)
                             )
                                { LayerId = lt["H细线"], };

                                modelSpace.AppendEntity(Array);
                                tr.AddNewlyCreatedDBObject(Array, true);
                                curWidth += topSp[i];
                                if (i == topSp.Count - 1 && isLastVisible)
                                {
                                    Array = new Solid(
                             refpt.C3D(0 + curWidth, 0, 0),
                             refpt.C3D(0.01 * scale + curWidth, 0, 0),
                              refpt.C3D(1 * scale + curWidth, 0.5 * scale, 0)
                             )
                                    { LayerId = lt["H细线"], };

                                    modelSpace.AppendEntity(Array);
                                    tr.AddNewlyCreatedDBObject(Array, true);
                                }
                            }
                        }
                        else
                        {
                            Array = new Solid(
                           refpt.C3D(0 + curWidth, 0, 0),
                           refpt.C3D(0.01 * scale + curWidth, 0, 0),
                            refpt.C3D(1 * scale + curWidth, 0.5 * scale, 0)
                           )
                            { LayerId = lt["H细线"], };

                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);
                        }
                        L = new Line(refpt.C3D(width + (1 + length) * scale, 0, 0), refpt.C3D(0, 0, 0))
                        { LayerId = lt["H细线"], };
                        modelSpace.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);
                        if (leftLength !=0)
                        {
                            L = new Line(refpt.C3D(width + (1 + length) * scale, 0, 0), refpt.C3D(width + (1 + length) * scale, leftLength, 0))
                            { LayerId = lt["H细线"], };
                            modelSpace.AppendEntity(L);
                            tr.AddNewlyCreatedDBObject(L, true);
                            if (leftLength > 0)
                                PositionPoint = refpt.C3D(width + (1 + length) * scale, leftLength+ cR * scale, 0);
                            else
                                PositionPoint = refpt.C3D(width + (1 + length) * scale, leftLength - cR * scale, 0);
                        }
                        else
                            PositionPoint = refpt.C3D(width + (1 + length) * scale + cR * scale, 0, 0);
                        break;
                    case ArrowDirection.South:  //下
                        refpt = refpt.C3D(0, -height);
                        if (leftSp.Count > 0)
                        {
                            for (int i = 0; i < leftSp.Count; i++)
                            {
                                Array = new Solid(
                             refpt.C3D(0, 0 + curHeight, 0),
                             refpt.C3D(0, 0.01 * scale + curHeight, 0),
                              refpt.C3D(0.5 * scale, 1 * scale + curHeight, 0)
                             )
                                { LayerId = lt["H细线"], };

                                modelSpace.AppendEntity(Array);
                                tr.AddNewlyCreatedDBObject(Array, true);
                                curHeight += leftSp[leftSp.Count - 1 - i];
                                if (i == leftSp.Count - 1 && isLastVisible)
                                {
                                    Array = new Solid(
                           refpt.C3D(0, 0 + curHeight, 0),
                           refpt.C3D(0, 0.01 * scale + curHeight, 0),
                            refpt.C3D(0.5 * scale, 1 * scale + curHeight, 0)
                           )
                                    { LayerId = lt["H细线"], };

                                    modelSpace.AppendEntity(Array);
                                    tr.AddNewlyCreatedDBObject(Array, true);
                                }
                            }
                        }
                        else
                        {
                            Array = new Solid(
                            refpt.C3D(0, 0 + curHeight, 0),
                            refpt.C3D(0, 0.01 * scale + curHeight, 0),
                             refpt.C3D(0.5 * scale, 1 * scale + curHeight, 0)
                            )
                            { LayerId = lt["H细线"], };

                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);
                        }
                        L = new Line(refpt.C3D(0, height + (1 + length) * scale, 0), refpt.C3D(0, 0, 0))
                        { LayerId = lt["H细线"], };
                        modelSpace.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);
                        if (leftLength > 0)
                        {
                            L = new Line(refpt.C3D(leftLength, height + (1 + length) * scale, 0), refpt.C3D(0, height + (1 + length) * scale, 0))
                            { LayerId = lt["H细线"], };
                            modelSpace.AppendEntity(L);
                            tr.AddNewlyCreatedDBObject(L, true);
                            PositionPoint = refpt.C3D(leftLength + cR * scale, height + (1 + length) * scale, 0);
                        }
                        else
                        {
                            PositionPoint = refpt.C3D(0, height + (1 + length) * scale + cR * scale, 0);
                        }
                        break;
                    case ArrowDirection.North:   //上
                        if (leftSp.Count > 0)
                        {
                            for (int i = 0; i < leftSp.Count; i++)
                            {
                                Array = new Solid(
                             refpt.C3D(0, 0 - curHeight, 0),
                             refpt.C3D(0, -0.01 * scale - curHeight, 0),
                              refpt.C3D(0.5 * scale, -1 * scale - curHeight, 0)
                             )
                                { LayerId = lt["H细线"], };

                                modelSpace.AppendEntity(Array);
                                tr.AddNewlyCreatedDBObject(Array, true);
                                curHeight += leftSp[i];
                                if (i == leftSp.Count-1 && isLastVisible)
                                {
                                    Array = new Solid(
                            refpt.C3D(0, 0 - curHeight, 0),
                            refpt.C3D(0, -0.01 * scale - curHeight, 0),
                             refpt.C3D(0.5 * scale, -1 * scale - curHeight, 0)
                            )
                                    { LayerId = lt["H细线"], };

                                    modelSpace.AppendEntity(Array);
                                    tr.AddNewlyCreatedDBObject(Array, true);
                                }
                            }
                        }
                        else
                        {
                            Array = new Solid(
                             refpt.C3D(0, 0 - curHeight, 0),
                             refpt.C3D(0, -0.01 * scale - curHeight, 0),
                              refpt.C3D(0.5 * scale, -1 * scale - curHeight, 0)
                             )
                            { LayerId = lt["H细线"], };

                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);
                        }
                        L = new Line(refpt.C3D(0, -height - (1 + length) * scale, 0), refpt.C3D(0, 0, 0))
                        { LayerId = lt["H细线"], };
                        modelSpace.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);
                        if (leftLength > 0)
                        {
                            L = new Line(refpt.C3D(leftLength, -height - (1 + length) * scale, 0), refpt.C3D(0, -height - (1 + length) * scale, 0))
                            { LayerId = lt["H细线"], };
                            modelSpace.AppendEntity(L);
                            tr.AddNewlyCreatedDBObject(L, true);
                            PositionPoint = refpt.C3D(leftLength + cR * scale, -height - (1 + length) * scale, 0);
                        }
                        else
                            PositionPoint = refpt.C3D(0, -height - (1 + length) * scale - cR * scale, 0);
                        break;
                    default:  //右
                        refpt = refpt.C3D(width, 0);
                        for (int i = 0; i < topSp.Count; i++)
                        {
                            Array = new Solid(
                             refpt.C3D(0 - curWidth, 0, 0),
                             refpt.C3D(-0.01 * scale - curWidth, 0, 0),
                              refpt.C3D(-1 * scale - curWidth, 0.5 * scale, 0)
                             )
                            { LayerId = lt["H细线"], };
                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);
                            curWidth += topSp[topSp.Count - 1 - i];
                        }
                        L = new Line(refpt.C3D(-width - (1 + length) * scale, 0, 0), refpt.C3D(0, 0, 0))
                        { LayerId = lt["H细线"], };
                        modelSpace.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);
                        PositionPoint = refpt.C3D(-width - (1 + length) * scale - cR * scale, 0, 0);
                        break;
                }
                ext = ext.Add(new Extents2d(Array.Bounds.Value.MinPoint.C2D(), Array.Bounds.Value.MaxPoint.C2D()));
                ext = ext.Add(new Extents2d(L.Bounds.Value.MinPoint.C2D(), L.Bounds.Value.MaxPoint.C2D()));
                txt.TextString = textstring.ToString();
                txt.Height = 2.5 * scale;
                txt.Position = PositionPoint.C3D();
                txt.HorizontalMode = TextHorizontalMode.TextCenter;
                txt.VerticalMode = TextVerticalMode.TextVerticalMid;
                txt.AlignmentPoint = PositionPoint.C3D();
                txt.TextStyleId = st[Extensions.curFont];
                txt.LayerId = lt["H标注"];
                //txt.ColorIndex = 4;
                txt.WidthFactor = 0.8;

                C2 = new Circle(PositionPoint.C3D(), Vector3d.ZAxis, cR * scale);
                C2.LayerId = lt["H标注"];
                //C2.ColorIndex = 4;
                modelSpace.AppendEntity(txt);
                tr.AddNewlyCreatedDBObject(txt, true);
                modelSpace.AppendEntity(C2);
                tr.AddNewlyCreatedDBObject(C2, true);
                ext = ext.Add(new Extents2d(txt.Bounds.Value.MinPoint.C2D(), txt.Bounds.Value.MaxPoint.C2D()));
                ext = ext.Add(new Extents2d(C2.Bounds.Value.MinPoint.C2D(), C2.Bounds.Value.MaxPoint.C2D()));
                tr.Commit();
            }
        }

        public static void CreateLineArrowDBNew(Database db, ref Extents2d ext, Point3d refpt, ArrowDirection arrDir, List<double> leftSp, List<double> topSp, string textstring = "1", string textstring1 = "2", double scale = 1, bool isLastVisible = true, double length = 0, double leftLength = 0)
        {
            double width = 0;
            double height = 0;
            width = topSp.Sum();
            height = leftSp.Sum();
            double curWidth = 0;
            double curHeight = 0;
            double cR = 2.5;
            DBText txt = new DBText();
            Circle C2 = new Circle();
            Point3d PositionPoint;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                Solid Array = new Solid();
                Line L = new Line() { LayerId = lt["H细线"] };
                switch (arrDir)
                {
                    case ArrowDirection.East:  //右
                        refpt = refpt.C3D(width, 0);
                        if (topSp.Count > 0)
                        {
                            for (int i = 0; i < topSp.Count; i++)
                            {
                                Array = new Solid(
                                 refpt.C3D(0 - curWidth, 0, 0),
                                 refpt.C3D(-0.01 * scale - curWidth, 0, 0),
                                  refpt.C3D(-1 * scale - curWidth, 0.5 * scale, 0)
                                 )
                                { LayerId = lt["H细线"], };
                                modelSpace.AppendEntity(Array);
                                tr.AddNewlyCreatedDBObject(Array, true);
                                curWidth += topSp[topSp.Count - 1 - i];
                                if (i == topSp.Count - 1 && isLastVisible)
                                {
                                    Array = new Solid(
                                 refpt.C3D(0 - curWidth, 0, 0),
                                 refpt.C3D(-0.01 * scale - curWidth, 0, 0),
                                  refpt.C3D(-1 * scale - curWidth, 0.5 * scale, 0)
                                 )
                                    { LayerId = lt["H细线"], };
                                    modelSpace.AppendEntity(Array);
                                    tr.AddNewlyCreatedDBObject(Array, true);
                                }
                            }
                        }
                        else
                        {
                            Array = new Solid(
                                 refpt.C3D(0 - curWidth, 0, 0),
                                 refpt.C3D(-0.01 * scale - curWidth, 0, 0),
                                  refpt.C3D(-1 * scale - curWidth, 0.5 * scale, 0)
                                 )
                            { LayerId = lt["H细线"], };
                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);
                        }
                        L = new Line(refpt.C3D(-width - (1 + length) * scale, 0, 0), refpt.C3D(0, 0, 0))
                        { LayerId = lt["H细线"], };
                        modelSpace.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);
                        if (leftLength > 0)
                        {
                            L = new Line(refpt.C3D(-width - (1 + length) * scale, 0, 0), refpt.C3D(-width - (1 + length) * scale, leftLength, 0))
                            { LayerId = lt["H细线"], };
                            modelSpace.AppendEntity(L);
                            tr.AddNewlyCreatedDBObject(L, true);
                            PositionPoint = refpt.C3D(-width - (1 + length) * scale, leftLength + cR * scale, 0);
                        }
                        else
                            PositionPoint = refpt.C3D(-width - (1 + length) * scale - cR * scale, 0, 0);
                        break;
                    case ArrowDirection.West:  //左
                        if (topSp.Count > 0)
                        {
                            for (int i = 0; i < topSp.Count; i++)
                            {
                                Array = new Solid(
                             refpt.C3D(0 + curWidth, 0, 0),
                             refpt.C3D(0.01 * scale + curWidth, 0, 0),
                              refpt.C3D(1 * scale + curWidth, 0.5 * scale, 0)
                             )
                                { LayerId = lt["H细线"], };

                                modelSpace.AppendEntity(Array);
                                tr.AddNewlyCreatedDBObject(Array, true);
                                curWidth += topSp[i];
                                if (i == topSp.Count - 1 && isLastVisible)
                                {
                                    Array = new Solid(
                             refpt.C3D(0 + curWidth, 0, 0),
                             refpt.C3D(0.01 * scale + curWidth, 0, 0),
                              refpt.C3D(1 * scale + curWidth, 0.5 * scale, 0)
                             )
                                    { LayerId = lt["H细线"], };

                                    modelSpace.AppendEntity(Array);
                                    tr.AddNewlyCreatedDBObject(Array, true);
                                }
                            }
                        }
                        else
                        {
                            Array = new Solid(
                           refpt.C3D(0 + curWidth, 0, 0),
                           refpt.C3D(0.01 * scale + curWidth, 0, 0),
                            refpt.C3D(1 * scale + curWidth, 0.5 * scale, 0)
                           )
                            { LayerId = lt["H细线"], };

                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);
                        }
                        L = new Line(refpt.C3D(width + (1 + length) * scale, 0, 0), refpt.C3D(0, 0, 0))
                        { LayerId = lt["H细线"], };
                        modelSpace.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);
                        if (leftLength > 0)
                        {
                            L = new Line(refpt.C3D(width + (1 + length) * scale, 0, 0), refpt.C3D(width + (1 + length) * scale, leftLength, 0))
                            { LayerId = lt["H细线"], };
                            modelSpace.AppendEntity(L);
                            tr.AddNewlyCreatedDBObject(L, true);
                            PositionPoint = refpt.C3D(width + (1 + length) * scale, leftLength + cR * scale, 0);
                        }
                        else
                            PositionPoint = refpt.C3D(width + (1 + length) * scale + cR * scale, 0, 0);
                        break;
                    case ArrowDirection.South:  //下
                        refpt = refpt.C3D(0, -height);
                        if (leftSp.Count > 0)
                        {
                            for (int i = 0; i < leftSp.Count; i++)
                            {
                                Array = new Solid(
                             refpt.C3D(0, 0 + curHeight, 0),
                             refpt.C3D(0, 0.01 * scale + curHeight, 0),
                              refpt.C3D(0.5 * scale, 1 * scale + curHeight, 0)
                             )
                                { LayerId = lt["H细线"], };

                                modelSpace.AppendEntity(Array);
                                tr.AddNewlyCreatedDBObject(Array, true);
                                curHeight += leftSp[leftSp.Count - 1 - i];
                                if (i == leftSp.Count - 1 && isLastVisible)
                                {
                                    Array = new Solid(
                           refpt.C3D(0, 0 + curHeight, 0),
                           refpt.C3D(0, 0.01 * scale + curHeight, 0),
                            refpt.C3D(0.5 * scale, 1 * scale + curHeight, 0)
                           )
                                    { LayerId = lt["H细线"], };

                                    modelSpace.AppendEntity(Array);
                                    tr.AddNewlyCreatedDBObject(Array, true);
                                }
                            }
                        }
                        else
                        {
                            Array = new Solid(
                            refpt.C3D(0, 0 + curHeight, 0),
                            refpt.C3D(0, 0.01 * scale + curHeight, 0),
                             refpt.C3D(0.5 * scale, 1 * scale + curHeight, 0)
                            )
                            { LayerId = lt["H细线"], };

                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);
                        }
                        L = new Line(refpt.C3D(0, height + (1 + length) * scale, 0), refpt.C3D(0, 0, 0))
                        { LayerId = lt["H细线"], };
                        modelSpace.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);
                        if (leftLength > 0)
                        {
                            L = new Line(refpt.C3D(leftLength, height + (1 + length) * scale, 0), refpt.C3D(0, height + (1 + length) * scale, 0))
                            { LayerId = lt["H细线"], };
                            modelSpace.AppendEntity(L);
                            tr.AddNewlyCreatedDBObject(L, true);
                            PositionPoint = refpt.C3D(leftLength + cR * scale, height + (1 + length) * scale, 0);
                        }
                        else
                        {
                            PositionPoint = refpt.C3D(0, height + (1 + length) * scale + cR * scale, 0);
                        }
                        break;
                    case ArrowDirection.North:   //上
                        if (leftSp.Count > 0)
                        {
                            for (int i = 0; i < leftSp.Count; i++)
                            {
                                Array = new Solid(
                             refpt.C3D(0, 0 - curHeight, 0),
                             refpt.C3D(0, -0.01 * scale - curHeight, 0),
                              refpt.C3D(0.5 * scale, -1 * scale - curHeight, 0)
                             )
                                { LayerId = lt["H细线"], };

                                modelSpace.AppendEntity(Array);
                                tr.AddNewlyCreatedDBObject(Array, true);
                                curHeight += leftSp[i];
                                if (i == leftSp.Count - 1 && isLastVisible)
                                {
                                    Array = new Solid(
                            refpt.C3D(0, 0 - curHeight, 0),
                            refpt.C3D(0, -0.01 * scale - curHeight, 0),
                             refpt.C3D(0.5 * scale, -1 * scale - curHeight, 0)
                            )
                                    { LayerId = lt["H细线"], };

                                    modelSpace.AppendEntity(Array);
                                    tr.AddNewlyCreatedDBObject(Array, true);
                                }
                            }
                        }
                        else
                        {
                            Array = new Solid(
                             refpt.C3D(0, 0 - curHeight, 0),
                             refpt.C3D(0, -0.01 * scale - curHeight, 0),
                              refpt.C3D(0.5 * scale, -1 * scale - curHeight, 0)
                             )
                            { LayerId = lt["H细线"], };

                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);
                        }
                        L = new Line(refpt.C3D(0, -height - (1 + length) * scale, 0), refpt.C3D(0, 0, 0))
                        { LayerId = lt["H细线"], };
                        modelSpace.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);
                        if (leftLength > 0)
                        {
                            L = new Line(refpt.C3D(leftLength, -height - (1 + length) * scale, 0), refpt.C3D(0, -height - (1 + length) * scale, 0))
                            { LayerId = lt["H细线"], };
                            modelSpace.AppendEntity(L);
                            tr.AddNewlyCreatedDBObject(L, true);
                            PositionPoint = refpt.C3D(leftLength + cR * scale, -height - (1 + length) * scale, 0);
                        }
                        else
                            PositionPoint = refpt.C3D(0, -height - (1 + length) * scale - cR * scale, 0);
                        break;
                    default:  //右
                        refpt = refpt.C3D(width, 0);
                        for (int i = 0; i < topSp.Count; i++)
                        {
                            Array = new Solid(
                             refpt.C3D(0 - curWidth, 0, 0),
                             refpt.C3D(-0.01 * scale - curWidth, 0, 0),
                              refpt.C3D(-1 * scale - curWidth, 0.5 * scale, 0)
                             )
                            { LayerId = lt["H细线"], };
                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);
                            curWidth += topSp[topSp.Count - 1 - i];
                        }
                        L = new Line(refpt.C3D(-width - (1 + length) * scale, 0, 0), refpt.C3D(0, 0, 0))
                        { LayerId = lt["H细线"], };
                        modelSpace.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);
                        PositionPoint = refpt.C3D(-width - (1 + length) * scale - cR * scale, 0, 0);
                        break;
                }
                ext = ext.Add(new Extents2d(Array.Bounds.Value.MinPoint.C2D(), Array.Bounds.Value.MaxPoint.C2D()));
                ext = ext.Add(new Extents2d(L.Bounds.Value.MinPoint.C2D(), L.Bounds.Value.MaxPoint.C2D()));
                txt.TextString = textstring.ToString();
                txt.Height = 2.5 * scale;
                txt.Position = PositionPoint.C3D();
                txt.HorizontalMode = TextHorizontalMode.TextCenter;
                txt.VerticalMode = TextVerticalMode.TextVerticalMid;
                txt.AlignmentPoint = PositionPoint.C3D();
                txt.TextStyleId = st[Extensions.curFont];
                txt.LayerId = lt["H标注"];
                //txt.ColorIndex = 4;
                txt.WidthFactor = 0.8;

                C2 = new Circle(PositionPoint.C3D(), Vector3d.ZAxis, cR * scale);
                C2.LayerId = lt["H标注"];
                //C2.ColorIndex = 4;
                modelSpace.AppendEntity(txt);
                tr.AddNewlyCreatedDBObject(txt, true);
                modelSpace.AppendEntity(C2);
                tr.AddNewlyCreatedDBObject(C2, true);
                ext = ext.Add(new Extents2d(txt.Bounds.Value.MinPoint.C2D(), txt.Bounds.Value.MaxPoint.C2D()));
                ext = ext.Add(new Extents2d(C2.Bounds.Value.MinPoint.C2D(), C2.Bounds.Value.MaxPoint.C2D()));
                DBText txt1 = new DBText();
                Circle C1 = new Circle();
                switch (arrDir)
                {
                  
                    case ArrowDirection.North:
           
                        txt1.TextString = textstring1.ToString();
                        txt1.Height = 2.5 * scale;
                        txt1.Position = PositionPoint.C3D(0,-cR * scale*2);
                        txt1.HorizontalMode = TextHorizontalMode.TextCenter;
                        txt1.VerticalMode = TextVerticalMode.TextVerticalMid;
                        txt1.AlignmentPoint = PositionPoint.C3D(0, -cR * scale * 2);
                        txt1.TextStyleId = st[Extensions.curFont];
                        txt1.LayerId = lt["H标注"];
                        //txt.ColorIndex = 4;
                        txt1.WidthFactor = 0.8;

                        C1 = new Circle(PositionPoint.C3D(0, -cR * scale * 2), Vector3d.ZAxis, cR * scale);
                        C1.LayerId = lt["H标注"];
                        //C2.ColorIndex = 4;
                        modelSpace.AppendEntity(txt1);
                        tr.AddNewlyCreatedDBObject(txt1, true);
                        modelSpace.AppendEntity(C1);
                        tr.AddNewlyCreatedDBObject(C1, true);
                        ext = ext.Add(new Extents2d(txt1.Bounds.Value.MinPoint.C2D(), txt1.Bounds.Value.MaxPoint.C2D()));
                        ext = ext.Add(new Extents2d(C1.Bounds.Value.MinPoint.C2D(), C1.Bounds.Value.MaxPoint.C2D()));
                        break;
                    case ArrowDirection.South:

                        txt1.TextString = textstring1.ToString();
                        txt1.Height = 2.5 * scale;
                        txt1.Position = PositionPoint.C3D(0, cR * scale * 2);
                        txt1.HorizontalMode = TextHorizontalMode.TextCenter;
                        txt1.VerticalMode = TextVerticalMode.TextVerticalMid;
                        txt1.AlignmentPoint = PositionPoint.C3D(0, cR * scale * 2);
                        txt1.TextStyleId = st[Extensions.curFont];
                        txt1.LayerId = lt["H标注"];
                        //txt.ColorIndex = 4;
                        txt1.WidthFactor = 0.8;

                        C1 = new Circle(PositionPoint.C3D(0, cR * scale * 2), Vector3d.ZAxis, cR * scale);
                        C1.LayerId = lt["H标注"];
                        //C2.ColorIndex = 4;
                        modelSpace.AppendEntity(txt1);
                        tr.AddNewlyCreatedDBObject(txt1, true);
                        modelSpace.AppendEntity(C1);
                        tr.AddNewlyCreatedDBObject(C1, true);
                        ext = ext.Add(new Extents2d(txt1.Bounds.Value.MinPoint.C2D(), txt1.Bounds.Value.MaxPoint.C2D()));
                        ext = ext.Add(new Extents2d(C1.Bounds.Value.MinPoint.C2D(), C1.Bounds.Value.MaxPoint.C2D()));
                        break;
                    case ArrowDirection.West:
    
                        txt1.TextString = textstring1.ToString();
                        txt1.Height = 2.5 * scale;
                        txt1.Position = PositionPoint.C3D(cR * scale * 2);
                        txt1.HorizontalMode = TextHorizontalMode.TextCenter;
                        txt1.VerticalMode = TextVerticalMode.TextVerticalMid;
                        txt1.AlignmentPoint = PositionPoint.C3D(cR * scale * 2);
                        txt1.TextStyleId = st[Extensions.curFont];
                        txt1.LayerId = lt["H标注"];
                        //txt.ColorIndex = 4;
                        txt1.WidthFactor = 0.8;

                        C1 = new Circle(PositionPoint.C3D( cR * scale * 2), Vector3d.ZAxis, cR * scale);
                        C1.LayerId = lt["H标注"];
                        //C2.ColorIndex = 4;
                        modelSpace.AppendEntity(txt1);
                        tr.AddNewlyCreatedDBObject(txt1, true);
                        modelSpace.AppendEntity(C1);
                        tr.AddNewlyCreatedDBObject(C1, true);
                        ext = ext.Add(new Extents2d(txt1.Bounds.Value.MinPoint.C2D(), txt1.Bounds.Value.MaxPoint.C2D()));
                        ext = ext.Add(new Extents2d(C1.Bounds.Value.MinPoint.C2D(), C1.Bounds.Value.MaxPoint.C2D()));
                        break;
                    case ArrowDirection.East:

                        txt1.TextString = textstring1.ToString();
                        txt1.Height = 2.5 * scale;
                        txt1.Position = PositionPoint.C3D(- cR * scale * 2);
                        txt1.HorizontalMode = TextHorizontalMode.TextCenter;
                        txt1.VerticalMode = TextVerticalMode.TextVerticalMid;
                        txt1.AlignmentPoint = PositionPoint.C3D(-cR * scale * 2);
                        txt1.TextStyleId = st[Extensions.curFont];
                        txt1.LayerId = lt["H标注"];
                        //txt.ColorIndex = 4;
                        txt1.WidthFactor = 0.8;

                        C1 = new Circle(PositionPoint.C3D(-cR * scale * 2), Vector3d.ZAxis, cR * scale);
                        C1.LayerId = lt["H标注"];
                        //C2.ColorIndex = 4;
                        modelSpace.AppendEntity(txt1);
                        tr.AddNewlyCreatedDBObject(txt1, true);
                        modelSpace.AppendEntity(C1);
                        tr.AddNewlyCreatedDBObject(C1, true);
                        ext = ext.Add(new Extents2d(txt1.Bounds.Value.MinPoint.C2D(), txt1.Bounds.Value.MaxPoint.C2D()));
                        ext = ext.Add(new Extents2d(C1.Bounds.Value.MinPoint.C2D(), C1.Bounds.Value.MaxPoint.C2D()));
                        break;
                }
                tr.Commit();
            }
        }

        public static void CreateLineArrowMultDBNew(Database db, ref Extents2d ext, Point3d refpt, ArrowDirection arrDir, List<double> leftSp, List<double> topSp, string textstring = "1", string textstring1 = "2", double scale = 1, bool isLastVisible = true, double length = 0, double leftLength = 0)
        {
            double width = 0;
            double height = 0;
            width = topSp.Sum();
            height = leftSp.Sum();
            double curWidth = 0;
            double curHeight = 0;
            double cR = 2.5;
            DBText txt = new DBText();
            Circle C2 = new Circle();

            DBText txt1 = new DBText();
            Circle C21 = new Circle();
            Point3d PositionPoint;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                Solid Array = new Solid();
                Line L = new Line() { LayerId = lt["H细线"] };
                switch (arrDir)
                {
                    case ArrowDirection.East:  //右
                        refpt = refpt.C3D(width, 0);
                        if (topSp.Count > 0)
                        {
                            for (int i = 0; i < topSp.Count; i++)
                            {
                                Array = new Solid(
                                 refpt.C3D(0 - curWidth, 0, 0),
                                 refpt.C3D(-0.01 * scale - curWidth, 0, 0),
                                  refpt.C3D(-1 * scale - curWidth, 0.5 * scale, 0)
                                 )
                                { LayerId = lt["H细线"], };
                                modelSpace.AppendEntity(Array);
                                tr.AddNewlyCreatedDBObject(Array, true);
                                curWidth += topSp[topSp.Count - 1 - i];
                                if (i == topSp.Count - 1 && isLastVisible)
                                {
                                    Array = new Solid(
                                 refpt.C3D(0 - curWidth, 0, 0),
                                 refpt.C3D(-0.01 * scale - curWidth, 0, 0),
                                  refpt.C3D(-1 * scale - curWidth, 0.5 * scale, 0)
                                 )
                                    { LayerId = lt["H细线"], };
                                    modelSpace.AppendEntity(Array);
                                    tr.AddNewlyCreatedDBObject(Array, true);
                                }
                            }
                        }
                        else
                        {
                            Array = new Solid(
                                 refpt.C3D(0 - curWidth, 0, 0),
                                 refpt.C3D(-0.01 * scale - curWidth, 0, 0),
                                  refpt.C3D(-1 * scale - curWidth, 0.5 * scale, 0)
                                 )
                            { LayerId = lt["H细线"], };
                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);
                        }
                        L = new Line(refpt.C3D(-width - (1 + length) * scale, 0, 0), refpt.C3D(0, 0, 0))
                        { LayerId = lt["H细线"], };
                        modelSpace.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);
                        PositionPoint = refpt.C3D(-width - (1 + length) * scale - cR * scale, 0, 0);
                        break;
                    case ArrowDirection.West:  //左
                        if (topSp.Count > 0)
                        {
                            for (int i = 0; i < topSp.Count; i++)
                            {
                                Array = new Solid(
                             refpt.C3D(0 + curWidth, 0, 0),
                             refpt.C3D(0.01 * scale + curWidth, 0, 0),
                              refpt.C3D(1 * scale + curWidth, 0.5 * scale, 0)
                             )
                                { LayerId = lt["H细线"], };

                                modelSpace.AppendEntity(Array);
                                tr.AddNewlyCreatedDBObject(Array, true);
                                curWidth += topSp[i];
                                if (i == topSp.Count - 1 && isLastVisible)
                                {
                                    Array = new Solid(
                             refpt.C3D(0 + curWidth, 0, 0),
                             refpt.C3D(0.01 * scale + curWidth, 0, 0),
                              refpt.C3D(1 * scale + curWidth, 0.5 * scale, 0)
                             )
                                    { LayerId = lt["H细线"], };

                                    modelSpace.AppendEntity(Array);
                                    tr.AddNewlyCreatedDBObject(Array, true);
                                }
                            }
                        }
                        else
                        {
                            Array = new Solid(
                           refpt.C3D(0 + curWidth, 0, 0),
                           refpt.C3D(0.01 * scale + curWidth, 0, 0),
                            refpt.C3D(1 * scale + curWidth, 0.5 * scale, 0)
                           )
                            { LayerId = lt["H细线"], };

                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);
                        }
                        L = new Line(refpt.C3D(width + (1 + length) * scale, 0, 0), refpt.C3D(0, 0, 0))
                        { LayerId = lt["H细线"], };
                        modelSpace.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);
                        PositionPoint = refpt.C3D(width + (1 + length) * scale + cR * scale, 0, 0);
                        break;
                    case ArrowDirection.South:  //下
                        refpt = refpt.C3D(0, -height);
                        if (leftSp.Count > 0)
                        {
                            for (int i = 0; i < leftSp.Count; i++)
                            {
                                Array = new Solid(
                             refpt.C3D(0, 0 + curHeight, 0),
                             refpt.C3D(0, 0.01 * scale + curHeight, 0),
                              refpt.C3D(0.5 * scale, 1 * scale + curHeight, 0)
                             )
                                { LayerId = lt["H细线"], };

                                modelSpace.AppendEntity(Array);
                                tr.AddNewlyCreatedDBObject(Array, true);
                                curHeight += leftSp[leftSp.Count - 1 - i];
                                if (i == leftSp.Count - 1 && isLastVisible)
                                {
                                    Array = new Solid(
                           refpt.C3D(0, 0 + curHeight, 0),
                           refpt.C3D(0, 0.01 * scale + curHeight, 0),
                            refpt.C3D(0.5 * scale, 1 * scale + curHeight, 0)
                           )
                                    { LayerId = lt["H细线"], };

                                    modelSpace.AppendEntity(Array);
                                    tr.AddNewlyCreatedDBObject(Array, true);
                                }
                            }
                        }
                        else
                        {
                            Array = new Solid(
                            refpt.C3D(0, 0 + curHeight, 0),
                            refpt.C3D(0, 0.01 * scale + curHeight, 0),
                             refpt.C3D(0.5 * scale, 1 * scale + curHeight, 0)
                            )
                            { LayerId = lt["H细线"], };

                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);
                        }
                        L = new Line(refpt.C3D(0, height + (1 + length) * scale, 0), refpt.C3D(0, 0, 0))
                        { LayerId = lt["H细线"], };
                        modelSpace.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);
                        if (leftLength > 0)
                        {
                            L = new Line(refpt.C3D(leftLength, height + (1 + length) * scale, 0), refpt.C3D(0, height + (1 + length) * scale, 0))
                            { LayerId = lt["H细线"], };
                            modelSpace.AppendEntity(L);
                            tr.AddNewlyCreatedDBObject(L, true);
                            PositionPoint = refpt.C3D(leftLength + cR * scale, height + (1 + length) * scale, 0);
                        }
                        else
                        {
                            PositionPoint = refpt.C3D(0, height + (1 + length) * scale + cR * scale, 0);
                        }
                        break;
                    case ArrowDirection.North:   //上
                        if (leftSp.Count > 0)
                        {
                            for (int i = 0; i < leftSp.Count; i++)
                            {
                                Array = new Solid(
                             refpt.C3D(0, 0 - curHeight, 0),
                             refpt.C3D(0, -0.01 * scale - curHeight, 0),
                              refpt.C3D(0.5 * scale, -1 * scale - curHeight, 0)
                             )
                                { LayerId = lt["H细线"], };

                                modelSpace.AppendEntity(Array);
                                tr.AddNewlyCreatedDBObject(Array, true);
                                curHeight += leftSp[i];
                                if (i == leftSp.Count && isLastVisible)
                                {
                                    Array = new Solid(
                            refpt.C3D(0, 0 - curHeight, 0),
                            refpt.C3D(0, -0.01 * scale - curHeight, 0),
                             refpt.C3D(0.5 * scale, -1 * scale - curHeight, 0)
                            )
                                    { LayerId = lt["H细线"], };

                                    modelSpace.AppendEntity(Array);
                                    tr.AddNewlyCreatedDBObject(Array, true);
                                }
                            }
                        }
                        else
                        {
                            Array = new Solid(
                             refpt.C3D(0, 0 - curHeight, 0),
                             refpt.C3D(0, -0.01 * scale - curHeight, 0),
                              refpt.C3D(0.5 * scale, -1 * scale - curHeight, 0)
                             )
                            { LayerId = lt["H细线"], };

                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);
                        }
                        L = new Line(refpt.C3D(0, -height - (1 + length) * scale, 0), refpt.C3D(0, 0, 0))
                        { LayerId = lt["H细线"], };
                        modelSpace.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);
                        if (leftLength > 0)
                        {
                            L = new Line(refpt.C3D(leftLength, -height - (1 + length) * scale, 0), refpt.C3D(0, -height - (1 + length) * scale, 0))
                            { LayerId = lt["H细线"], };
                            modelSpace.AppendEntity(L);
                            tr.AddNewlyCreatedDBObject(L, true);
                            PositionPoint = refpt.C3D(leftLength + cR * scale, -height - (1 + length) * scale, 0);
                        }
                        else
                            PositionPoint = refpt.C3D(0, -height - (1 + length) * scale - cR * scale, 0);
                        break;
                    default:  //右
                        refpt = refpt.C3D(width, 0);
                        for (int i = 0; i < topSp.Count; i++)
                        {
                            Array = new Solid(
                             refpt.C3D(0 - curWidth, 0, 0),
                             refpt.C3D(-0.01 * scale - curWidth, 0, 0),
                              refpt.C3D(-1 * scale - curWidth, 0.5 * scale, 0)
                             )
                            { LayerId = lt["H细线"], };
                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);
                            curWidth += topSp[topSp.Count - 1 - i];
                        }
                        L = new Line(refpt.C3D(-width - (1 + length) * scale, 0, 0), refpt.C3D(0, 0, 0))
                        { LayerId = lt["H细线"], };
                        modelSpace.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);
                        PositionPoint = refpt.C3D(-width - (1 + length) * scale - cR * scale, 0, 0);
                        break;
                }
                ext = ext.Add(new Extents2d(Array.Bounds.Value.MinPoint.C2D(), Array.Bounds.Value.MaxPoint.C2D()));
                ext = ext.Add(new Extents2d(L.Bounds.Value.MinPoint.C2D(), L.Bounds.Value.MaxPoint.C2D()));
                txt.TextString = textstring.ToString();
                txt.Height = 2.5 * scale;
                txt.Position = PositionPoint.C3D();
                txt.HorizontalMode = TextHorizontalMode.TextCenter;
                txt.VerticalMode = TextVerticalMode.TextVerticalMid;
                txt.AlignmentPoint = PositionPoint.C3D();
                txt.TextStyleId = st[Extensions.curFont];
                txt.LayerId = lt["标注"];
                //txt.ColorIndex = 4;
                txt.WidthFactor = 0.8;

                C2 = new Circle(PositionPoint.C3D(), Vector3d.ZAxis, cR * scale);
                C2.LayerId = lt["标注"];
                //C2.ColorIndex = 4;
                modelSpace.AppendEntity(txt);
                tr.AddNewlyCreatedDBObject(txt, true);
                modelSpace.AppendEntity(C2);
                tr.AddNewlyCreatedDBObject(C2, true);
                ext = ext.Add(new Extents2d(txt.Bounds.Value.MinPoint.C2D(), txt.Bounds.Value.MaxPoint.C2D()));
                ext = ext.Add(new Extents2d(C2.Bounds.Value.MinPoint.C2D(), C2.Bounds.Value.MaxPoint.C2D()));
                if (arrDir == ArrowDirection.East)
                {
                    txt1.TextString = textstring1.ToString();
                    txt1.Height = 2.5 * scale;
                    txt1.Position = PositionPoint.C3D(-cR * scale * 2);
                    txt1.HorizontalMode = TextHorizontalMode.TextCenter;
                    txt1.VerticalMode = TextVerticalMode.TextVerticalMid;
                    txt1.AlignmentPoint = PositionPoint.C3D(-cR * scale * 2);
                    txt1.TextStyleId = st[Extensions.curFont];
                    txt1.LayerId = lt["标注"];
                    //txt.ColorIndex = 4;
                    txt1.WidthFactor = 0.8;

                    C21 = new Circle(PositionPoint.C3D(-cR * scale * 2), Vector3d.ZAxis, cR * scale);
                    C21.LayerId = lt["标注"];
                    //C2.ColorIndex = 4;
                    modelSpace.AppendEntity(txt1);
                    tr.AddNewlyCreatedDBObject(txt1, true);
                    modelSpace.AppendEntity(C21);
                    tr.AddNewlyCreatedDBObject(C21, true);
                    ext = ext.Add(new Extents2d(txt1.Bounds.Value.MinPoint.C2D(), txt1.Bounds.Value.MaxPoint.C2D()));
                    ext = ext.Add(new Extents2d(C21.Bounds.Value.MinPoint.C2D(), C21.Bounds.Value.MaxPoint.C2D()));
                }
                else
                {
                    txt1.TextString = textstring1.ToString();
                    txt1.Height = 2.5 * scale;
                    txt1.Position = PositionPoint.C3D(cR * scale * 2);
                    txt1.HorizontalMode = TextHorizontalMode.TextCenter;
                    txt1.VerticalMode = TextVerticalMode.TextVerticalMid;
                    txt1.AlignmentPoint = PositionPoint.C3D(cR * scale * 2);
                    txt1.TextStyleId = st[Extensions.curFont];
                    txt1.LayerId = lt["标注"];
                    //txt.ColorIndex = 4;
                    txt1.WidthFactor = 0.8;

                    C21 = new Circle(PositionPoint.C3D(cR * scale * 2), Vector3d.ZAxis, cR * scale);
                    C21.LayerId = lt["标注"];
                    //C2.ColorIndex = 4;
                    modelSpace.AppendEntity(txt1);
                    tr.AddNewlyCreatedDBObject(txt1, true);
                    modelSpace.AppendEntity(C21);
                    tr.AddNewlyCreatedDBObject(C21, true);
                    ext = ext.Add(new Extents2d(txt1.Bounds.Value.MinPoint.C2D(), txt1.Bounds.Value.MaxPoint.C2D()));
                    ext = ext.Add(new Extents2d(C21.Bounds.Value.MinPoint.C2D(), C21.Bounds.Value.MaxPoint.C2D()));
                }
                tr.Commit();
            }
        }

        #region pile 
        /// <summary>
        /// 钢筋笼立面
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="pt">绘制起点</param>
        /// <param name="radius1">最外侧圆半径</param>
        /// <param name="radius2">中间圆半径</param>
        /// <param name="radius3">最内侧圆半径param>
        /// <param name="rebarNum">圆环内钢筋数量</param>
        /// <param name="T1"></param>
        /// <param name="T2"></param>
        /// <param name="T3"></param>
        /// <param name="scale"></param>
        public static void CreateFacadeReinforcementCage(Database db, ref Extents2d ext,
            Point3d pt, double radius1, double radius2, double radius3, double rebarNum,
            string T1, string T2, string T3, double scale, double Radia = 30)
        {
            DBObjectCollection res = new DBObjectCollection();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                #region 圆环
                // 外圆
                Circle exCircle = new Circle(pt.Add(new Vector3d(radius1, 0, 0)), Vector3d.ZAxis, radius1) { LayerId = lt["H粗线"] };
                res.Add(exCircle);
                ext = ext.Add(new Extents2d(exCircle.Bounds.Value.MinPoint.C2D(), exCircle.Bounds.Value.MaxPoint.C2D()));

                // 中间圆
                Circle circle = new Circle(pt.Add(new Vector3d(radius1, 0, 0)), Vector3d.ZAxis, radius2) { LayerId = lt["H粗线"] };
                res.Add(circle);
                ext = ext.Add(new Extents2d(circle.Bounds.Value.MinPoint.C2D(), circle.Bounds.Value.MaxPoint.C2D()));

                // 内圆
                Circle innerCircle = new Circle(pt.Add(new Vector3d(radius1, 0, 0)), Vector3d.ZAxis, radius3) { LayerId = lt["H粗线"] };
                ext = ext.Add(new Extents2d(innerCircle.Bounds.Value.MinPoint.C2D(), innerCircle.Bounds.Value.MaxPoint.C2D()));
                res.Add(innerCircle);

                // 钢筋半径
                double reBarRadius = Radia;

                // 绘制环内圆点
                double height = 0;
                double width = 0;
                double radiusInterval = radius2 - reBarRadius;

                // 圆点中心坐标
                List<Point3d> list = new List<Point3d>();
                #region 绘制环内圆点
                for (int i = 0; i < rebarNum; ++i)
                {
                    // 计算圆点
                    Point3d center = pt.Add(new Vector3d(2 * radius1 - reBarRadius, 0, 0));

                    double angle = 360 / rebarNum * i;

                    if (angle > 0 && angle < 90)
                    {
                        angle = GeTools.DegreeToRadian(angle);
                        height = Math.Abs(radiusInterval * Math.Sin(angle));
                        width = -Math.Abs(radiusInterval * Math.Cos(angle));
                    }
                    else if (angle > 90 && angle < 180)
                    {
                        angle = GeTools.DegreeToRadian(180 - angle);
                        height = Math.Abs(radiusInterval * Math.Sin(angle));
                        width = Math.Abs(radiusInterval * Math.Cos(angle));
                    }
                    else if (angle > 180 && angle < 270)
                    {
                        angle = GeTools.DegreeToRadian(270 - angle);
                        height = -Math.Abs(radiusInterval * Math.Cos(angle));
                        width = Math.Abs(radiusInterval * Math.Sin(angle));
                    }
                    else if (angle > 270 && angle < 360)
                    {
                        angle = GeTools.DegreeToRadian(360 - angle);
                        height = -Math.Abs(radiusInterval * Math.Sin(angle));
                        width = -Math.Abs(radiusInterval * Math.Cos(angle));
                    }
                    else if (angle == 0 || angle == 360)
                    {
                        height = -radiusInterval * Math.Sin(0);
                        width = -radiusInterval * Math.Cos(0);
                    }
                    else if (angle == 90)
                    {
                        height = radiusInterval * Math.Cos(0);
                        width = radiusInterval * Math.Sin(0);
                    }
                    else if (angle == 180)
                    {
                        angle = 360 - angle;
                        height = radiusInterval * Math.Sin(0);
                        width = radiusInterval * Math.Cos(0);
                    }
                    else if (angle == 270)
                    {
                        angle = 360 - angle;
                        height = -radiusInterval * Math.Cos(0);
                        width = radiusInterval * Math.Sin(0);
                    }

                    center = pt.Add(new Vector3d(radius1 + width, height, 0));
                    list.Add(center);
                    CreateSolidCircle(db, ref ext, center, reBarRadius);
                }
                #endregion
                #endregion

                #region 标记
                // 圆心坐标
                Point3d circleCenter = pt.C3D(radius1);

                // 外圆半径标记
                //DBObjectCollection res1 = DimPloter.ArrowLine(db, ref ext, ArrowDirection.East, circleCenter, radius1, scale,30);
                //DBObjectCollection res2 = TextPloter.PlotText(db,db, ref ext, TextPloter.eTxtLocation.E_TOP,
                //    circleCenter.C2D(radius1 / 2, 5), string.Format("R{0}", radius1), scale, Extensions.curFont,
                //    GeTools.DegreeToRadian(0));
                //var TX1 = Matrix3d.Rotation(GeTools.DegreeToRadian(30), Vector3d.ZAxis, circleCenter.C3D());

                RebarDimPloter.ArrowLineAndText(db, ref ext, ArrowDirection.East, circleCenter, radius1, scale, 30, string.Format("R{0}", radius1), TextPloter.eTxtLocation.E_TOP, Extensions.curFont);
                //foreach (DBObject item in res1)
                //{
                //    Entity pr = (Entity)item;
                //    pr.TransformBy(TX1);
                //}
                //foreach (DBObject item in res2)
                //{
                //    Entity pr = (Entity)item;
                //    pr.TransformBy(TX1);
                //}

                // 中间圆半径标记
                //res1 = DimPloter.ArrowLine(db, ref ext, ArrowDirection.East, circleCenter, radius2, scale,-30);
                //res2 = TextPloter.PlotText(db,db, ref ext, TextPloter.eTxtLocation.E_TOP,
                //    circleCenter.C2D(radius2 / 2, 5), string.Format("R{0}", radius2), scale, Extensions.curFont,
                //    GeTools.DegreeToRadian(0));
                RebarDimPloter.ArrowLineAndText(db, ref ext, ArrowDirection.East, circleCenter, radius2, scale, -30, string.Format("R{0}", radius2), TextPloter.eTxtLocation.E_TOP, Extensions.curFont);
                //TX1 = Matrix3d.Rotation(GeTools.DegreeToRadian(-30), Vector3d.ZAxis, circleCenter.C3D());
                //foreach (DBObject item in res1)
                //{
                //    Entity pr = (Entity)item;
                //    pr.TransformBy(TX1);
                //}
                //foreach (DBObject item in res2)
                //{
                //    Entity pr = (Entity)item;
                //    pr.TransformBy(TX1);
                //}

                // 内圆半径标记
                //res1 = DimPloter.ArrowLine(db, ref ext, ArrowDirection.West, circleCenter, radius3, scale,15);
                //res2 = TextPloter.PlotText(db,db, ref ext, TextPloter.eTxtLocation.E_TOP,
                //    circleCenter.C2D(-radius3 / 2, 5), string.Format("R{0}", radius3), scale, Extensions.curFont,
                //    GeTools.DegreeToRadian(0));
                RebarDimPloter.ArrowLineAndText(db, ref ext, ArrowDirection.West, circleCenter, radius3, scale, 15, string.Format("R{0}", radius3), TextPloter.eTxtLocation.E_TOP, Extensions.curFont);
                //TX1 = Matrix3d.Rotation(GeTools.DegreeToRadian(15), Vector3d.ZAxis, circleCenter.C3D());
                //foreach (DBObject item in res1)
                //{
                //    Entity pr = (Entity)item;
                //    pr.TransformBy(TX1);
                //}
                //foreach (DBObject item in res2)
                //{
                //    Entity pr = (Entity)item;
                //    pr.TransformBy(TX1);
                //}
                #endregion

                #region 标注
                if (list != null && list.Count > 0)
                {
                    Point3d p1, p2, p3 = new Point3d(), p4, p5;
                    double offsetX = radius1 / 2;
                    double offsetY = radius1 / 2;
                    int index = list.Count / 4 + 1;
                    if (index < list.Count)
                    {
                        p1 = list[index];
                        p3 = p1.C3D(-offsetX / 2, -offsetY);

                        Polyline Line1 = new Polyline() { Closed = false, LayerId = lt["H细线"] };
                        Line1.AddVertexAt(0, p1.C2D(), 0, 0, 0);
                        Line1.AddVertexAt(0, p3.C2D(), 0, 0, 0);
                        ext = ext.Add(new Extents2d(Line1.Bounds.Value.MinPoint.C2D(), Line1.Bounds.Value.MaxPoint.C2D()));
                        res.Add(Line1);
                    }

                    if (index + 1 < list.Count)
                    {
                        p2 = list[index + 1];
                        p4 = new Point3d(p2.X - offsetX / 2, p3.Y, 0);
                        Polyline Line2 = new Polyline() { Closed = false, LayerId = lt["H细线"] };
                        Line2.AddVertexAt(0, p2.C2D(), 0, 0, 0);
                        Line2.AddVertexAt(0, p4.C2D(), 0, 0, 0);
                        ext = ext.Add(new Extents2d(Line2.Bounds.Value.MinPoint.C2D(), Line2.Bounds.Value.MaxPoint.C2D()));
                        res.Add(Line2);

                        p5 = p3.C3D(-offsetX * 0.5);
                        Line2 = new Polyline() { Closed = false, LayerId = lt["H细线"] };
                        Line2.AddVertexAt(0, p4.C2D(), 0, 0, 0);
                        Line2.AddVertexAt(0, p5.C2D(), 0, 0, 0);
                        ext = ext.Add(new Extents2d(Line2.Bounds.Value.MinPoint.C2D(), Line2.Bounds.Value.MaxPoint.C2D()));
                        res.Add(Line2);

                        // 圆形标记
                        DimPloter.CircularMark(db, ref ext, p5.C3D(-2.5 * scale * 2), "1", Extensions.curFont, scale);
                    }

                    // 圆环标记
                    // 外圆
                    double valueX = radius1 * Math.Cos(GeTools.DegreeToRadian(45));
                    Point3d pt1 = circleCenter.C3D(radius1);
                    RebarDimPloter.CreateHookLineMark(db, ref ext, pt1, "7", (radius1 - radius2) * 10, scale, 0);

                    // 中间圆
                    valueX = radius2 * Math.Cos(GeTools.DegreeToRadian(45));
                    pt1 = circleCenter.C3D(valueX, -valueX);
                    RebarDimPloter.CreateHookLineMark(db, ref ext, pt1, "5", (radius1 - radius2) * 10, scale, -45);

                    //// 内圆
                    valueX = radius3 * Math.Cos(GeTools.DegreeToRadian(225));
                    pt1 = circleCenter.C3D(valueX, valueX);
                    RebarDimPloter.CreateHookLineMark(db, ref ext, pt1, "3", (radius1 - radius2) * 10, scale, 225);
                }
                #endregion

                #region 声测管
                double soundPipeRadius = reBarRadius * 2;
                // 声测管布控
                int soundPipeNum = radius1 * 2 / (800) <= 1 ? 2 : 2 + (int)(radius1 * 2 / (800));
                // 声空管距圆心距离一致
                height = 0;
                width = 0;
                double thick = 20;
                List<Point3d> soundPipelist = new List<Point3d>();
                radiusInterval = radius3 - soundPipeRadius - thick;
                for (int i = 0; i < soundPipeNum; ++i)
                {
                    Point3d center = pt;
                    double angle = 360 / soundPipeNum * i;
                    if (angle > 0 && angle < 90)
                    {
                        angle = GeTools.DegreeToRadian(angle);
                        height = Math.Abs(radiusInterval * Math.Sin(angle));
                        width = -Math.Abs(radiusInterval * Math.Cos(angle));
                    }
                    else if (angle > 90 && angle < 180)
                    {
                        angle = GeTools.DegreeToRadian(180 - angle);
                        height = Math.Abs(radiusInterval * Math.Sin(angle));
                        width = Math.Abs(radiusInterval * Math.Cos(angle));
                    }
                    else if (angle > 180 && angle < 270)
                    {
                        angle = GeTools.DegreeToRadian(270 - angle);
                        height = -Math.Abs(radiusInterval * Math.Cos(angle));
                        width = Math.Abs(radiusInterval * Math.Sin(angle));
                    }
                    else if (angle > 270 && angle < 360)
                    {
                        angle = GeTools.DegreeToRadian(360 - angle);
                        height = -Math.Abs(radiusInterval * Math.Sin(angle));
                        width = -Math.Abs(radiusInterval * Math.Cos(angle));
                    }
                    else if (angle == 0 || angle == 360)
                    {
                        height = -radiusInterval * Math.Sin(0);
                        width = -radiusInterval * Math.Cos(0);
                    }
                    else if (angle == 90)
                    {
                        height = radiusInterval * Math.Cos(0);
                        width = radiusInterval * Math.Sin(0);
                    }
                    else if (angle == 180)
                    {
                        angle = 360 - angle;
                        height = radiusInterval * Math.Sin(0);
                        width = radiusInterval * Math.Cos(0);
                    }
                    else if (angle == 270)
                    {
                        angle = 360 - angle;
                        height = -radiusInterval * Math.Cos(0);
                        width = radiusInterval * Math.Sin(0);
                    }

                    center = pt.Add(new Vector3d(radius1 + width, height, 0));
                    soundPipelist.Add(center);
                }

                for (int i = 0; i < soundPipelist.Count; ++i)
                {
                    circle = new Circle(soundPipelist[i].C3D(), Vector3d.ZAxis, soundPipeRadius) { LayerId = lt["H粗线"] };
                    res.Add(circle);
                    ext = ext.Add(new Extents2d(circle.Bounds.Value.MinPoint.C2D(), circle.Bounds.Value.MaxPoint.C2D()));
                }
                RebarDimPloter.CreateLeadWireWithoutCircleMark(db, ref ext, soundPipelist[soundPipelist.Count - 1], "声测管", "", Extensions.curFont, scale);
                #endregion

                // 两点之间的间距标注
                double arg = Math.Atan(Math.Abs(list[3].Y - list[2].Y) / Math.Abs(list[3].X - list[2].X));
                arg = GeTools.RadianToDegree(arg);
                RotatedDimension Dim2 = DimPloter.AddRotDim(db, ref ext, list[2].C3D(), list[3].C3D(), list[2].C3D(-5 * scale, 5 * scale), scale, arg);
                //ext = ext.Add(new Extents2d(Dim2.Bounds.Value.MinPoint.C2D(), Dim2.Bounds.Value.MaxPoint.C2D()));
                //res.Add(Dim2);
                //ext = ext.Add(new Extents2d(Dim2.Bounds.Value.MinPoint.C2D(), Dim2.Bounds.Value.MaxPoint.C2D()));
                foreach (DBObject drawitem in res)
                {
                    recorder.AppendEntity((Entity)drawitem);
                    tr.AddNewlyCreatedDBObject(drawitem, true);
                }

                tr.Commit();

            }
        }

        /// <summary>
        /// 三角撑
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="startPoint"></param>
        /// <param name="radius"></param>
        /// <param name="T1"></param>
        /// <param name="T2"></param>
        /// <param name="T3"></param>
        /// <param name="scale"></param>
        /// <param name="isDrawTriangleTie">是否绘制三角撑</param>
        /// <param name="isDrawFaceWeld">是否绘制焊接面</param>
        public static void CreatePileTriangleTie(Database db, ref Extents2d ext, Point3d startPoint,
            double radius, string T1, string T2, int T3, double scale, bool isDrawTriangleTie = true,
            bool isDrawFaceWeld = true, string replaceDim = "")
        {
            DBObjectCollection res = new DBObjectCollection();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                // 圆
                Circle exCircle = new Circle(startPoint.Add(new Vector3d(radius, 0, 0)), Vector3d.ZAxis, radius) { LayerId = lt["H粗线"] };
                res.Add(exCircle);
                ext = ext.Add(new Extents2d(exCircle.Bounds.Value.MinPoint.C2D(), exCircle.Bounds.Value.MaxPoint.C2D()));

                // 三角撑
                int soundPipeNum = 3;

                Point3d p1, p2, p3, center;
                center = startPoint.C3D(radius);
                p1 = startPoint.C3D(radius, radius);
                p2 = center.C3D(-radius * Math.Cos(GeTools.DegreeToRadian(30)), -radius * Math.Sin(GeTools.DegreeToRadian(30)));
                p3 = center.C3D(radius * Math.Cos(GeTools.DegreeToRadian(30)), -radius * Math.Sin(GeTools.DegreeToRadian(30)));

                if (isDrawTriangleTie)
                {
                    Polyline pl1 = new Polyline() { Closed = true, LayerId = lt["H粗线"] };
                    pl1.AddVertexAt(0, p1.C2D(), 0, 0, 0);
                    pl1.AddVertexAt(1, p2.C2D(), 0, 0, 0);
                    pl1.AddVertexAt(2, p3.C2D(), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                    res.Add(pl1);
                }
                #region 引线
                double width1 = 0, height = 0;
                MText txt1 = TextPloter.GetTextActualWidth(db, T1, scale, out width1, out height, 2.5, Extensions.curFont);

                double width2 = 0;
                MText txt2 = TextPloter.GetTextActualWidth(db, T2, scale, out width2, out height, 2.5, Extensions.curFont);

                double lineWidth = width1 > width2 ? width1 : width2;

                RebarDimPloter.RebarWire(db, ref ext, center.C2D(radius * Math.Cos(GeTools.DegreeToRadian(45)), radius * Math.Sin(GeTools.DegreeToRadian(45))), T1, T2, T3,
                    GeTools.DegreeToRadian(0), Extensions.curFont, scale);

                // 直径标记
                RebarDimPloter.CreateDiameterMark(db, ref ext, startPoint, eArrow.E_ARROW_DOUBLE_SIDE_ARROW, radius * 2,
                    "D253.4", scale, -15);

                if (isDrawTriangleTie)
                {
                    // 支撑架标记
                    double offsetWidth = radius / 10;
                    Point3d p4 = center.C3D(radius / 2 * Math.Cos(GeTools.DegreeToRadian(30)),
                        radius / 2 * Math.Sin(GeTools.DegreeToRadian(30)));

                    // 圆形标记
                    RebarDimPloter.CreateHookLineMark(db, ref ext, p4, "2", offsetWidth, scale);
                }
                // 焊接面
                if (isDrawFaceWeld)
                {
                    RebarDimPloter.CreateFaceWeld(db, ref ext, startPoint.Add(new Vector3d(radius, 0, 0)), radius, scale, replaceDim);
                    RebarDimPloter.CreateLeadWireWithoutCircleMark(db, ref ext, startPoint.C3D(radius, -radius),
                        "单面焊", "", Extensions.curFont, scale);
                }

                #endregion

                foreach (DBObject drawitem in res)
                {
                    recorder.AppendEntity((Entity)drawitem);
                    tr.AddNewlyCreatedDBObject(drawitem, true);
                }

                tr.Commit();
            }
        }

        public static void CreatePileReber(Database db, ref Extents2d ext, Point3d startPoint,
 double radius, string T1, string T2, int T3, double scale, bool isDrawTriangleTie = true,
 bool isDrawFaceWeld = true, string replaceDim = "")
        {
            DBObjectCollection res = new DBObjectCollection();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                Polyline pl1 = new Polyline() { Closed = true, LayerId = lt["H粗线"] };
                pl1.AddVertexAt(0, startPoint.C2D(), 0, 0, 0);
                pl1.AddVertexAt(1, startPoint.C2D(2 * radius), 0, 0, 0);
                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                res.Add(pl1);
                DBText txt = new DBText();
                txt.TextString = T2;
                txt.Height = 2.5 * scale;
                txt.Position = startPoint.C3D(radius, -2.5 * scale);
                txt.HorizontalMode = TextHorizontalMode.TextCenter;
                txt.VerticalMode = TextVerticalMode.TextVerticalMid;
                txt.AlignmentPoint = startPoint.C3D(radius, -2.5 * scale);
                txt.TextStyleId = st[Extensions.curFont];
                txt.LayerId = lt["H标注"];
                txt.WidthFactor = 0.8;
                res.Add(txt);
                ext = ext.Add(new Extents2d(txt.Bounds.Value.MinPoint.C2D(), txt.Bounds.Value.MaxPoint.C2D()));

                #region 引线

                RebarDimPloter.RebarWire(db, ref ext, startPoint.C2D(radius), T1, T2, T3,
                    GeTools.DegreeToRadian(0), Extensions.curFont, scale);


                #endregion

                foreach (DBObject drawitem in res)
                {
                    recorder.AppendEntity((Entity)drawitem);
                    tr.AddNewlyCreatedDBObject(drawitem, true);
                }

                tr.Commit();
            }
        }
        #endregion

        #region plinth
        public static void CreateGirdElev(Database db, ref Extents2d ext, Point2d insertPoint,
    double tWidth, double dia, List<double> topSp,
    int numLayer, double step, out List<Point3d> rebarCC)
        {
            //width = 0;
            double height = 0;
            double RebarWidth = topSp.Sum();
            double radius = dia * 0.5;
            rebarCC = new List<Point3d>();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                double x0 = RebarWidth * -0.5;
                double y0 = 0;
                for (int m = 0; m < numLayer; m++)
                {
                    //画线
                    //Polyline line = new Polyline() { Closed = false, Layer = "粗线" };//定义不封闭的Polyline 平面虚线
                    //line.AddVertexAt(0, insertPoint.C2D(-0.5*tWidth, -dH), 0, 0, 0);
                    //line.AddVertexAt(1, insertPoint.C2D(0.5*tWidth, -dH), 0, 0, 0);
                    Line line = new Line(insertPoint.C3D(-0.5 * tWidth, y0), insertPoint.C3D(0.5 * tWidth, y0));
                    line.LayerId = lt["H粗线"];
                    //line.ColorIndex = 1;
                    recorder.AppendEntity(line);
                    tr.AddNewlyCreatedDBObject(line, true);
                    ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.C2D(), line.Bounds.Value.MaxPoint.C2D()));
                    #region 
                    //x0 = 0;
                    for (int i = 0; i < topSp.Count + 1; i++)
                    {
                        x0 = RebarWidth * (-0.5) + topSp.GetRange(0, i).Sum();
                        //画圆
                        Circle ci = new Circle();
                        ci.Center = insertPoint.C3D(x0, y0 + (Math.Sign(step)) * (radius + 1));
                        if (m == 0)
                        {
                            rebarCC.Add(ci.Center);

                        }
                        ci.Radius = radius;
                        ci.SetDatabaseDefaults();//用来把圆的颜色、图层、线型、打印样式、可见性等属性设为实体所在的数据库的默认值
                        ci.LayerId = lt["H标注"];
                        recorder.AppendEntity(ci);
                        tr.AddNewlyCreatedDBObject(ci, true);
                        ext = ext.Add(new Extents2d(ci.Bounds.Value.MinPoint.C2D(), ci.Bounds.Value.MaxPoint.C2D()));
                        //圆填充
                        ObjectIdCollection collection = new ObjectIdCollection();
                        collection.Add(ci.ObjectId);
                        Hatch hatch = new Hatch();
                        hatch.Elevation = 0;
                        hatch.HatchStyle = HatchStyle.Normal;
                        hatch.LayerId = lt["H标注"];
                        hatch.SetDatabaseDefaults();
                        hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID"); //设置填充图案
                        hatch.AppendLoop(HatchLoopTypes.Default, collection); //设置填充边界 //
                        hatch.EvaluateHatch(true);
                        hatch.LayerId = lt["H标注"];
                        recorder.AppendEntity(hatch);
                        tr.AddNewlyCreatedDBObject(hatch, true);
                    }
                    y0 += step;
                    #endregion
                }

                tr.Commit();
            }
            rebarCC.Sort((x, y) => x.X.CompareTo(y.X));
        }
        public static void CreateGirdElevNew(Database db, ref Extents2d ext, Point2d insertPoint,
    double tWidth, double dia, List<double> topSp,
    int numLayer, double step, out List<Point3d> rebarCC,bool isAddSide=true)
        {
            //width = 0;
            double height = 0;
            double RebarWidth = topSp.Sum();
            double radius = dia * 0.5;
            rebarCC = new List<Point3d>();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                double x0 = RebarWidth * -0.5;
                double y0 = 0;
                for (int m = 0; m < numLayer; m++)
                {
                    //画线
                    //Polyline line = new Polyline() { Closed = false, Layer = "粗线" };//定义不封闭的Polyline 平面虚线
                    //line.AddVertexAt(0, insertPoint.C2D(-0.5*tWidth, -dH), 0, 0, 0);
                    //line.AddVertexAt(1, insertPoint.C2D(0.5*tWidth, -dH), 0, 0, 0);
                    Line line = new Line(insertPoint.C3D(-0.5 * tWidth, y0), insertPoint.C3D(0.5 * tWidth, y0));
                    if(!isAddSide)
                        line = new Line(insertPoint.C3D(-0.5 * tWidth+ topSp[0]*0.5, y0), insertPoint.C3D(0.5 * tWidth- topSp[0] * 0.5, y0));
                    line.LayerId = lt["H粗线"];
                    //line.ColorIndex = 1;
                    recorder.AppendEntity(line);
                    tr.AddNewlyCreatedDBObject(line, true);
                    ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.C2D(), line.Bounds.Value.MaxPoint.C2D()));
                    #region 
                    //x0 = 0;
                    for (int i = 0; i < topSp.Count + 1; i++)
                    {
                        x0 = RebarWidth * (-0.5) + topSp.GetRange(0, i).Sum();
                        //画圆
                        Circle ci = new Circle();
                        ci.Center = insertPoint.C3D(x0, y0 + (Math.Sign(step)) * (radius*2));
                        if (m == 0)
                        {
                            rebarCC.Add(ci.Center);

                        }
                        ci.Radius = radius;
                        ci.SetDatabaseDefaults();//用来把圆的颜色、图层、线型、打印样式、可见性等属性设为实体所在的数据库的默认值
                        ci.LayerId = lt["H标注"];
                        recorder.AppendEntity(ci);
                        tr.AddNewlyCreatedDBObject(ci, true);
                        ext = ext.Add(new Extents2d(ci.Bounds.Value.MinPoint.C2D(), ci.Bounds.Value.MaxPoint.C2D()));
                        //圆填充
                        ObjectIdCollection collection = new ObjectIdCollection();
                        collection.Add(ci.ObjectId);
                        Hatch hatch = new Hatch();
                        hatch.Elevation = 0;
                        hatch.HatchStyle = HatchStyle.Normal;
                        hatch.LayerId = lt["H标注"];
                        hatch.SetDatabaseDefaults();
                        hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID"); //设置填充图案
                        hatch.AppendLoop(HatchLoopTypes.Default, collection); //设置填充边界 //
                        hatch.EvaluateHatch(true);
                        hatch.LayerId = lt["H标注"];
                        recorder.AppendEntity(hatch);
                        tr.AddNewlyCreatedDBObject(hatch, true);
                    }
                    y0 += step;
                    #endregion
                }

                tr.Commit();
            }
            rebarCC.Sort((x, y) => x.X.CompareTo(y.X));
        }

        public static void AddBJByDirectiong(Database db, ref Extents2d ext, Point3d insertPt, ArrowDirection arrDir, string textstring = "A", double scale = 1)
        {
            double width = 1.5 * scale;
            double height = 3 * scale;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                Polyline line = new Polyline() { Closed = false, LayerId = lt["H细线"] };//定义不封闭的Polyline 平面虚线
                DBText txt = new DBText();
                txt.TextString = textstring.ToString();
                txt.Height = 2.5 * scale;
                txt.HorizontalMode = TextHorizontalMode.TextCenter;
                txt.VerticalMode = TextVerticalMode.TextVerticalMid;

                txt.TextStyleId = st[Extensions.curFont];
                txt.LayerId = lt["H标注"];
                txt.WidthFactor = 0.8;
                #region 箭头
                Solid Array = new Solid();
                Array.LayerId = lt["H标注"];
                Point3d refpt;
                switch (arrDir)
                {
                    case ArrowDirection.North:  //上
                        refpt = insertPt.C3D(width + 2.65 * scale, 0);
                        Array = new Solid(
                             refpt.C3D(0, 0, 0),
                             refpt.C3D(-2.65 * scale, 0, 0),
                              refpt.C3D(-2 * scale, 0.5 * scale, 0)
                             )
                        {/* Color = Color.FromColorIndex(ColorMethod.ByAci, 7),*/ LayerId = lt["H标注"] };
                        modelSpace.AppendEntity(Array);
                        tr.AddNewlyCreatedDBObject(Array, true);

                        line.AddVertexAt(0, insertPt.C2D(width), 0, 0, 0);
                        line.AddVertexAt(1, insertPt.C2D(), 0, 0, 0);
                        line.AddVertexAt(2, insertPt.C2D(0, -height), 0, 0, 0);
                        modelSpace.AppendEntity(line);
                        tr.AddNewlyCreatedDBObject(line, true);

                        txt.Position = insertPt.C3D(1 * scale, -1.5 * scale);
                        txt.AlignmentPoint = insertPt.C3D(1 * scale, -1.5 * scale);
                        break;
                    case ArrowDirection.South:  //下

                        refpt = insertPt.C3D(width + 2.65 * scale, 0);
                        Array = new Solid(
                           refpt.C3D(0, 0, 0),
                           refpt.C3D(-2.65 * scale, 0, 0),
                            refpt.C3D(-2 * scale, -0.5 * scale, 0)
                           )
                        { /*Color = Color.FromColorIndex(ColorMethod.ByAci, 7),*/ LayerId = lt["H标注"] };

                        modelSpace.AppendEntity(Array);
                        tr.AddNewlyCreatedDBObject(Array, true);
                        line.AddVertexAt(0, insertPt.C2D(width), 0, 0, 0);
                        line.AddVertexAt(1, insertPt.C2D(), 0, 0, 0);
                        line.AddVertexAt(2, insertPt.C2D(0, height), 0, 0, 0);
                        modelSpace.AppendEntity(line);
                        tr.AddNewlyCreatedDBObject(line, true);

                        txt.Position = insertPt.C3D(1 * scale, 1.5 * scale);
                        txt.AlignmentPoint = insertPt.C3D(1 * scale, 1.5 * scale);
                        break;
                    case ArrowDirection.West:  //左
                        width = 3 * scale;
                        height = 1.5 * scale;
                        refpt = insertPt.C3D(0, -height - 2.65 * scale);
                        Array = new Solid(
                            refpt.C3D(0, 0, 0),
                            refpt.C3D(0, 2.65 * scale, 0),
                             refpt.C3D(-0.5 * scale, 2 * scale, 0)
                            )
                        { /*Color = Color.FromColorIndex(ColorMethod.ByAci, 7), */LayerId = lt["H标注"] };

                        modelSpace.AppendEntity(Array);
                        tr.AddNewlyCreatedDBObject(Array, true);

                        line.AddVertexAt(0, insertPt.C2D(width), 0, 0, 0);
                        line.AddVertexAt(1, insertPt.C2D(), 0, 0, 0);
                        line.AddVertexAt(2, insertPt.C2D(0, -height), 0, 0, 0);
                        modelSpace.AppendEntity(line);
                        tr.AddNewlyCreatedDBObject(line, true);

                        txt.Position = insertPt.C3D(1 * scale, -1.5 * scale);
                        txt.AlignmentPoint = insertPt.C3D(1 * scale, -1.5 * scale);
                        break;
                    case ArrowDirection.East:   //右
                        width = 3 * scale;
                        height = 1.5 * scale;
                        refpt = insertPt.C3D(0, -height - 2.65 * scale);
                        Array = new Solid(
                             refpt.C3D(0, 0, 0),
                             refpt.C3D(0, 2.65 * scale, 0),
                              refpt.C3D(0.5 * scale, 2 * scale, 0)
                             )
                        { /*Color = Color.FromColorIndex(ColorMethod.ByAci, 7),*/ LayerId = lt["H标注"] };

                        modelSpace.AppendEntity(Array);
                        tr.AddNewlyCreatedDBObject(Array, true);
                        line.AddVertexAt(0, insertPt.C2D(-width), 0, 0, 0);
                        line.AddVertexAt(1, insertPt.C2D(), 0, 0, 0);
                        line.AddVertexAt(2, insertPt.C2D(0, -height), 0, 0, 0);
                        modelSpace.AppendEntity(line);
                        tr.AddNewlyCreatedDBObject(line, true);

                        txt.Position = insertPt.C3D(-1 * scale, -1.5 * scale);
                        txt.AlignmentPoint = insertPt.C3D(-1 * scale, -1.5 * scale);
                        break;
                }
                ext = ext.Add(new Extents2d(Array.Bounds.Value.MinPoint.C2D(), Array.Bounds.Value.MaxPoint.C2D()));
                ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.C2D(), line.Bounds.Value.MaxPoint.C2D()));
                #endregion

                #region

                modelSpace.AppendEntity(txt);
                tr.AddNewlyCreatedDBObject(txt, true);
                ext = ext.Add(new Extents2d(txt.Bounds.Value.MinPoint.C2D(), txt.Bounds.Value.MaxPoint.C2D()));
                #endregion
                tr.Commit();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="db"></param>
        /// <param name="Point"></param>
        /// <param name="leftSp"></param>
        /// <param name="topSp"></param>
        /// <param name="ext"></param>
        /// <param name="exLength"></param>
        /// <param name="PtsLeft">左侧标注基点</param>
        /// <param name="PtsTop">顶部标注基点</param>
        public static void CreateLineGrid(Database db, Point2d Point, List<double> leftSp, List<double> topSp, ref Extents2d ext, double exLength,
            out List<Point3d> PtsLeft, out List<Point3d> PtsTop)
        {
            double width = 0;
            double height = 0;
            width = topSp.Sum();
            height = leftSp.Sum();
            double curWidth = 0;
            double curHeight = 0;

            //             输出横纵向PT列表
            PtsLeft = new List<Point3d>(); // 左侧列表
            PtsTop = new List<Point3d>();  // 顶部列表
            //             输出横纵向PT列表

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                for (int m = 0; m < leftSp.Count; m++)
                {
                    //画线
                    Polyline line = new Polyline() { Closed = false, LayerId = lt["H粗线"] };//定义不封闭的Polyline 平面虚线
                    line.AddVertexAt(0, Point.C2D(0 - exLength, -curHeight), 0, 0, 0);
                    PtsLeft.Add(Point.C3D(0, -curHeight));
                    line.AddVertexAt(1, Point.C2D(width + exLength, -curHeight), 0, 0, 0);
                    recorder.AppendEntity(line);
                    tr.AddNewlyCreatedDBObject(line, true);
                    ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.C2D(), line.Bounds.Value.MaxPoint.C2D()));
                    #region 
                    curWidth = 0;
                    for (int i = 0; i < topSp.Count; i++)
                    {
                        if (m == 0)
                        {
                            //画线
                            line = new Polyline() { Closed = false, LayerId = lt["H粗线"] };//定义不封闭的Polyline 平面虚线
                            line.AddVertexAt(0, Point.C2D(curWidth, 0 + exLength), 0, 0, 0);
                            PtsTop.Add(Point.C3D(curWidth, 0));
                            line.AddVertexAt(1, Point.C2D(curWidth, -height - exLength), 0, 0, 0);
                            recorder.AppendEntity(line);
                            tr.AddNewlyCreatedDBObject(line, true);
                            ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.C2D(), line.Bounds.Value.MaxPoint.C2D()));
                        }

                        curWidth += topSp[i];
                        if (i == topSp.Count - 1)
                        {
                            if (m == 0)
                            {
                                //画线
                                line = new Polyline() { Closed = false, LayerId = lt["H粗线"] };//定义不封闭的Polyline 平面虚线
                                line.AddVertexAt(0, Point.C2D(curWidth, 0 + exLength), 0, 0, 0);
                                PtsTop.Add(Point.C3D(curWidth, 0));
                                line.AddVertexAt(1, Point.C2D(curWidth, -height - exLength), 0, 0, 0);
                                recorder.AppendEntity(line);
                                tr.AddNewlyCreatedDBObject(line, true);
                                ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.C2D(), line.Bounds.Value.MaxPoint.C2D()));
                            }
                        }


                    }
                    curHeight += leftSp[m];
                    if (m == leftSp.Count - 1)
                    {
                        //画线
                        line = new Polyline() { Closed = false, LayerId = lt["H粗线"] };//定义不封闭的Polyline 平面虚线
                        line.AddVertexAt(0, Point.C2D(0 - exLength, -height), 0, 0, 0);
                        PtsLeft.Add(Point.C3D(0, -height));
                        line.AddVertexAt(1, Point.C2D(width + exLength, -height), 0, 0, 0);
                        recorder.AppendEntity(line);
                        tr.AddNewlyCreatedDBObject(line, true);
                        ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.C2D(), line.Bounds.Value.MaxPoint.C2D()));
                    }
                    #endregion
                }
                tr.Commit();

            }

            PtsTop.Sort((x, y) => x.X.CompareTo(y.X));
            PtsLeft.Sort((x, y) => x.Y.CompareTo(y.Y));
        }
        public static void CreateLineGridNew(Database db, Point2d Point, List<double> leftSp, List<double> topSp, ref Extents2d ext, double exLength,
        out List<Point3d> PtsLeft, out List<Point3d> PtsTop)
        {
            double width = 0;
            double height = 0;
            width = topSp.Sum();
            height = leftSp.Sum();
            double curWidth = 0;
            double curHeight = 0;

            //             输出横纵向PT列表
            PtsLeft = new List<Point3d>(); // 左侧列表
            PtsTop = new List<Point3d>();  // 顶部列表
            //             输出横纵向PT列表

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                for (int m = 0; m < leftSp.Count; m++)
                {
                    //画线
                    Polyline line = new Polyline() { Closed = false, LayerId = lt["H粗线"] };//定义不封闭的Polyline 平面虚线
                    line.AddVertexAt(0, Point.C2D(0 - exLength, -curHeight), 0, 0, 0);
                    PtsLeft.Add(Point.C3D(0, -curHeight));
                    line.AddVertexAt(1, Point.C2D(width + exLength, -curHeight), 0, 0, 0);
                    recorder.AppendEntity(line);
                    tr.AddNewlyCreatedDBObject(line, true);
                    ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.C2D(), line.Bounds.Value.MaxPoint.C2D()));
                    #region 
                    curWidth = 0;
                    for (int i = 0; i < topSp.Count; i++)
                    {
                        if (m == 0)
                        {
                            //画线
                            line = new Polyline() { Closed = false, LayerId = lt["H粗线"] };//定义不封闭的Polyline 平面虚线
                            line.AddVertexAt(0, Point.C2D(curWidth, 0 + exLength), 0, 0, 0);
                            PtsTop.Add(Point.C3D(curWidth, 0));
                            line.AddVertexAt(1, Point.C2D(curWidth, -height - exLength), 0, 0, 0);
                            recorder.AppendEntity(line);
                            tr.AddNewlyCreatedDBObject(line, true);
                            ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.C2D(), line.Bounds.Value.MaxPoint.C2D()));
                        }

                        curWidth += topSp[i];
                        if (i == topSp.Count - 1)
                        {
                            if (m == 0)
                            {
                                //画线
                                line = new Polyline() { Closed = false, LayerId = lt["H粗线"] };//定义不封闭的Polyline 平面虚线
                                line.AddVertexAt(0, Point.C2D(curWidth, 0 + exLength), 0, 0, 0);
                                PtsTop.Add(Point.C3D(curWidth, 0));
                                line.AddVertexAt(1, Point.C2D(curWidth, -height - exLength), 0, 0, 0);
                                recorder.AppendEntity(line);
                                tr.AddNewlyCreatedDBObject(line, true);
                                ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.C2D(), line.Bounds.Value.MaxPoint.C2D()));
                            }
                        }


                    }
                    curHeight += leftSp[m];
                    if (m == leftSp.Count - 1)
                    {
                        //画线
                        line = new Polyline() { Closed = false, LayerId = lt["H粗线"] };//定义不封闭的Polyline 平面虚线
                        line.AddVertexAt(0, Point.C2D(0 - exLength, -height), 0, 0, 0);
                        PtsLeft.Add(Point.C3D(0, -height));
                        line.AddVertexAt(1, Point.C2D(width + exLength, -height), 0, 0, 0);
                        recorder.AppendEntity(line);
                        tr.AddNewlyCreatedDBObject(line, true);
                        ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.C2D(), line.Bounds.Value.MaxPoint.C2D()));
                    }
                    #endregion
                }
                tr.Commit();

            }

            PtsTop.Sort((x, y) => x.X.CompareTo(y.X));
            PtsLeft.Sort((x, y) => x.Y.CompareTo(y.Y));
        }

        public static void CreateMultiLineCicle(Database db, ref Extents2d ext, Point3d refpt, List<Point3d> listP, string textstring = "1", double scale = 1)
        {

            double cR = 2.5;
            DBText txt = new DBText();
            Circle C2 = new Circle();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                bool isUp = true;
                if (listP.Count > 0)
                {
                    foreach (var p in listP)
                    {
                        Line line = new Line(p, refpt);
                        line.LayerId = lt["H细线"];
                        modelSpace.AppendEntity(line);
                        tr.AddNewlyCreatedDBObject(line, true);
                        ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.C2D(), line.Bounds.Value.MaxPoint.C2D()));
                    }
                    if (listP[0].Y > refpt.Y)
                    {
                        isUp = false;
                    }
                }
                double height = cR * scale;
                if (!isUp)
                    height = -cR * scale;
                txt.TextString = textstring.ToString();
                txt.Height = 2.5 * scale;
                txt.Position = refpt.C3D(0, height);
                txt.HorizontalMode = TextHorizontalMode.TextCenter;
                txt.VerticalMode = TextVerticalMode.TextVerticalMid;
                txt.AlignmentPoint = refpt.C3D(0, height);
                txt.TextStyleId = st[Extensions.curFont];
                //txt.ColorIndex = 4;
                txt.LayerId = lt["H细线"];
                txt.WidthFactor = 0.8;

                C2 = new Circle(refpt.C3D(0, height), Vector3d.ZAxis, cR * scale);
                C2.LayerId = lt["H细线"];
                //C2.ColorIndex = 4;
                modelSpace.AppendEntity(txt);
                tr.AddNewlyCreatedDBObject(txt, true);
                modelSpace.AppendEntity(C2);
                tr.AddNewlyCreatedDBObject(C2, true);
                ext = ext.Add(new Extents2d(txt.Bounds.Value.MinPoint.C2D(), txt.Bounds.Value.MaxPoint.C2D()));
                ext = ext.Add(new Extents2d(C2.Bounds.Value.MinPoint.C2D(), C2.Bounds.Value.MaxPoint.C2D()));
                tr.Commit();
            }
        }

        /// <summary>
        /// 绘制钢筋模型
        /// </summary>
        /// <param name="db"></param>
        /// <param name="T1">左边参数</param>
        /// <param name="T2">右边参数</param>
        /// <param name="T3">横线参数</param>
        /// <param name="T4">引线上部参数</param>
        /// <param name="T5">引线下部参数</param>
        /// <param name="T6">引线圆内参数</param>
        /// <param name="hLeft">左边线长</param>
        /// <param name="hRight">右边线长</param>
        /// <param name="width">横线长度</param>
        /// <param name="Rotation">旋转家督</param>
        /// <param name="scale">比例</param>
        /// <returns></returns>
        public static void CreateRebarModel(Database db, ref Extents2d ext, Point2d startPoint, string T1, string T2, string T3, string T4, string T5,
            int T6, double hLeft, double hRight, double width, double Rotation, double scale = 100)
        {
            DBObjectCollection res = new DBObjectCollection();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                #region 绘制钢筋和引线
                // 绘制钢筋
                Polyline rebarLine = new Polyline() { Closed = false, LayerId = lt["H细线"], };
                Point2d p1 = startPoint.C2D(-width / 2); ;
                Point2d p2 = p1.C2D(0, -hLeft);
                Point2d p3 = startPoint.C2D(width / 2);
                Point2d p4 = p3.C2D(0, -hRight);
                rebarLine.AddVertexAt(0, p4, 0, 0, 0);
                rebarLine.AddVertexAt(1, p3, 0, 0, 0);
                rebarLine.AddVertexAt(2, p1, 0, 0, 0);
                rebarLine.AddVertexAt(3, p2, 0, 0, 0);
                res.Add(rebarLine);
                ext = ext.Add(new Extents2d(rebarLine.Bounds.Value.MinPoint.C2D(), rebarLine.Bounds.Value.MaxPoint.C2D()));

                // 文字标注
                //Point2d pt1 = p1.C2D(0, -hLeft / 2);
                //DBObjectCollection res1 = TextPloter.PlotText(db,db, ref ext, TextPloter.eTxtLocation.E_LEFT, pt1, T1, scale, Extensions.curFont, GeTools.DegreeToRadian(90));

                //Point2d pt2 = p3.C2D(0, -hRight / 2);
                //DBObjectCollection res2 = TextPloter.PlotText(db,db, ref ext, TextPloter.eTxtLocation.E_RIGHT, pt2, T2, scale, Extensions.curFont, GeTools.DegreeToRadian(90));

                // 横线文字
                //Point2d pt3 = startPoint.C2D();
                //DBObjectCollection res3 = TextPloter.PlotText(db,db, ref ext, TextPloter.eTxtLocation.E_TOP, pt3, T3, scale, Extensions.curFont, GeTools.DegreeToRadian(0));

                // 引线位置
                Point2d wirePt = p3.C2D(-width / 3, 0);
                if (Rotation == 0 || Rotation == 360)
                {
                    wirePt = p2.C2D();
                }
                else if (Rotation == 90)
                {
                    wirePt = startPoint.C2D();
                }
                else if (Rotation == 180)
                {
                    wirePt = startPoint.C2D();
                }
                else if (Rotation == 270)
                {
                    wirePt = startPoint.C2D(0, width / 4);
                }
                // 钢筋引线
                RebarDimPloter.RebarWire(db, ref ext, wirePt, T4, T5, T6,
                   0, Extensions.curFont, scale);

                var TX1 = Matrix3d.Rotation(GeTools.DegreeToRadian(Rotation), Vector3d.ZAxis, startPoint.C3D());
                foreach (DBObject item in res)
                {
                    Entity pr = (Entity)item;
                    pr.TransformBy(TX1);
                }

                foreach (DBObject drawitem in res)
                {
                    recorder.AppendEntity((Entity)drawitem);
                    tr.AddNewlyCreatedDBObject(drawitem, true);
                }
                #endregion

                #region 绘制文字标注
                // 旋转文字使符合阅读习惯
                double txtRotation = Rotation;
                Point2d txtPt = startPoint;
                DBObjectCollection res1 = new DBObjectCollection();
                DBObjectCollection res2 = new DBObjectCollection();
                DBObjectCollection res3 = new DBObjectCollection();
                Point2d pt1 = Point2d.Origin;
                Point2d pt2 = Point2d.Origin;
                Point2d pt3 = Point2d.Origin;
                double txtRota1 = 0;
                double txtRota2 = 0;
                double txtRota3 = 0;
                TextPloter.eTxtLocation elocal1 = TextPloter.eTxtLocation.E_TOP;
                TextPloter.eTxtLocation elocal2 = TextPloter.eTxtLocation.E_TOP;
                TextPloter.eTxtLocation elocal3 = TextPloter.eTxtLocation.E_TOP;
                string txt1 = T1;
                string txt2 = T2;
                string txt3 = T3;

                if (Rotation == 0 || Rotation == 360)
                {
                    // 文字标注
                    pt1 = p1.C2D(-scale, -hLeft / 2);
                    pt2 = p3.C2D(scale, -hRight / 2);

                    // 横线文字
                    pt3 = startPoint.C2D(0, scale);
                    elocal1 = TextPloter.eTxtLocation.E_LEFT;
                    elocal2 = TextPloter.eTxtLocation.E_RIGHT;
                    elocal3 = TextPloter.eTxtLocation.E_TOP;
                    txtRota1 = 90;
                    txtRota2 = 90;
                    txtRota3 = 0;

                    txt1 = T1;
                    txt2 = T2;
                    txt3 = T3;
                }
                else if (Rotation == 90)
                {
                    // 文字标注
                    pt1 = startPoint.C2D(hRight / 2, width / 2 + scale);
                    pt2 = startPoint.C2D(hLeft / 2, -width / 2 - scale);

                    // 横线文字
                    pt3 = startPoint.C2D(-scale);

                    elocal1 = TextPloter.eTxtLocation.E_TOP;
                    elocal2 = TextPloter.eTxtLocation.E_BOTTOM;
                    elocal3 = TextPloter.eTxtLocation.E_LEFT;
                    txtRota1 = 0;
                    txtRota2 = 0;
                    txtRota3 = 90;

                    txt1 = T2;
                    txt2 = T1;
                    txt3 = T3;
                }
                else if (Rotation == 180)
                {
                    // 文字标注
                    pt1 = startPoint.C2D(-width / 2 - scale, hRight / 2);
                    pt2 = startPoint.C2D(width / 2 + scale, hLeft / 2);

                    // 横线文字
                    pt3 = startPoint.C2D(0, -scale);

                    elocal1 = TextPloter.eTxtLocation.E_LEFT;
                    elocal2 = TextPloter.eTxtLocation.E_RIGHT;
                    elocal3 = TextPloter.eTxtLocation.E_BOTTOM;
                    txtRota1 = 90;
                    txtRota2 = 90;
                    txtRota3 = 0;

                    txt1 = T2;
                    txt2 = T1;
                    txt3 = T3;
                }
                else if (Rotation == 270)
                {
                    // 文字标注
                    pt1 = startPoint.C2D(-hRight / 2, -width / 2 - scale * 4);
                    pt2 = startPoint.C2D(-hLeft / 2, width / 2 + scale);

                    // 横线文字
                    pt3 = startPoint.C2D(scale * 4);

                    elocal1 = TextPloter.eTxtLocation.E_TOP;
                    elocal2 = TextPloter.eTxtLocation.E_RIGHT;
                    elocal3 = TextPloter.eTxtLocation.E_BOTTOM;

                    txtRota1 = 0;
                    txtRota2 = 0;
                    txtRota3 = 90;

                    txt1 = T2;
                    txt2 = T1;
                    txt3 = T3;
                }

                // 文字标注
                res1 = TextPloter.PlotText(db, ref ext, elocal1, pt1, txt1, scale, Extensions.curFont, GeTools.DegreeToRadian(txtRota1));
                res2 = TextPloter.PlotText(db, ref ext, elocal2, pt2, txt2, scale, Extensions.curFont, GeTools.DegreeToRadian(txtRota2));

                // 横线文字
                res3 = TextPloter.PlotText(db, ref ext, elocal3, pt3, txt3, scale, Extensions.curFont, GeTools.DegreeToRadian(txtRota3));
                #endregion
                tr.Commit();
            }
        }

        #endregion
    }
}
